php - Print Variable returned from API -


i have simple script below:

<?php     header('content-type: text/plain; charset=utf-8;');      $file = file_get_contents("http://weather.justcode.us/api.php?city=suzhou");     print_r(json_decode($file)); ?> 

and returns

stdclass object (     [apiversion] => 1.0     [data] => stdclass object         (             [location] => suzhou, chn             [temperature] => 68             [skytext] => clear             [humidity] => 60             [wind] => 13             [date] => 2013-05-04             [day] => saturday         )  ) 

how print (for example) data->location or data->date? oh, , apologies in advance if simple question.

try this,

<?php header('content-type: text/plain; charset=utf-8;');  $file = file_get_contents("http://weather.justcode.us/api.php?city=suzhou"); $values= json_decode($file); $data=$values->data; echo $data->location;  ?> 

output

   suzhou, chn 

here can access data like,

  $data->location,data->date etc 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -