I'm trying to get the last price in USD from this coin:
<?php
$json = file_get_contents('https://api.coinmarketcap.com/v2/ticker/2424/');
echo $json;
?>
I tried two different options on the JSON object like [0]['price]
Nothing works.
I'm trying to get the last price in USD from this coin:
<?php
$json = file_get_contents('https://api.coinmarketcap.com/v2/ticker/2424/');
echo $json;
?>
I tried two different options on the JSON object like [0]['price]
Nothing works.
The response from coinmarketcap is in JSON, so you need to json_decode it.
The second paramter of json_decode lets you decide if its a object or array. For an array, mark this as true
<?php
$json = file_get_contents('https://api.coinmarketcap.com/v2/ticker/2424/');
$objResponse = json_decode($json, true);
echo $objResponse['data']['quotes']['USD']['price'];