1

Hello I'm coming from Get JSON object from URL

I tried to get marketCap->usd.

Can anyone tell me what I'm doing wrong please?

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'http://coinmarketcap.northpole.ro/api/v5/ZCL.json');
$result = curl_exec($ch);
curl_close($ch);

$obj = json_decode($result);
echo $result->marketCap->usd;
Community
  • 1
  • 1
user204415
  • 307
  • 1
  • 4
  • 20

2 Answers2

1

Change echo $result->marketCap->usd; for echo $obj->marketCap->usd;

You have saved the data decoded in $obj.

Dez
  • 5,702
  • 8
  • 42
  • 51
1

Last line of your code should be

echo $obj->marketCap->usd;