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
Post a Comment