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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -