0

Hi I have used curl to get some json api data and that is all working fine. I have ran into a problem when trying to get a specific value. I have decoded the json into an array but I still cant seem to get a specific value.

Here is my code:

$curl = curl_init();

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_URL, 'https://bittrex.com/api/v1.1/public/getcurrencies');

$result = curl_exec($curl);

curl_close($curl);

$json = json_decode($result, true);

print_r($json);

so if you go to this url https://bittrex.com/api/v1.1/public/getcurrencies you can see the data I am pulling in. I want to get the value of a Currency.

I tried changing my print to this print_r($json['Currency']); that returned nothing. I also tried this print_r($json[1]); which I thought would at least return something but yet again I got no response.

I have run print_r(gettype($json)); that returned an array so it is 100% an array.

Luke Rayner
  • 391
  • 6
  • 20
  • 1
    it's in 'result', as you see in the data you've linked to. `$json['result'][0]['Currency']` – Jeff Sep 23 '17 at 00:55
  • @Jeff what do I do to get the cointype of something by using the Currency name – Luke Rayner Sep 23 '17 at 00:57
  • just loop through that array to find it or use one of the [native array functions](http://php.net/manual/en/ref.array.php) – Jeff Sep 23 '17 at 01:00

1 Answers1

0

The result of that call is indeed an array, but it's not structured that way. To get the currency of the first result, you'll have to do print_r($json['result'][0]['Currency']), print_r($json['result'][1]['Currency']) for the second result, and so on.

EDIT: Jeff beat me to it.

José A. Zapata
  • 1,187
  • 1
  • 6
  • 12