How to parse cryptocurrency JSON to PHP string variables?

  arrays, cryptocurrency, json, parsing, php

I am working with the following API and code in order to parse JSON results into PHP string variables. The returned array looks simple enough but my code does not seem to work. I am grateful for any suggestions. Thanks!

  <?php

  $target_file = "https://api.nomics.com/v1/currencies/ticker? 
  key=570d36adac132ba61224813b90027e237107233f&ids=BTC";
  $json = file_get_contents($target_file);

  //Decode JSON
  $json_data = json_decode($json,true);

  foreach ($json_data[‘Array’] as $coinarray)
   { 
     $id = $coinarray[‘id’];
     $name = $coinarray[‘name’];
     echo "ID: $id";
     echo "Name: $name";
   }

   ?>

Source: Ask PHP

LEAVE A COMMENT