連想配列にします。
<?php $url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=130010"; $json = file_get_contents($url); $json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN'); $arr = json_decode($json,true); echo('<pre>'); print_r($arr); echo('</pre>'); ?>
では、東京の今日の天気を表示させてみましょう。
<?php $url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=130010"; $json = file_get_contents($url); $json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN'); $arr = json_decode($json,true); $time = strtotime($arr[description][publicTime]); echo "<b>東京:今日の天気</b><br>"; echo $arr[forecasts][0][telop]."<br>"; echo $arr[description]."<br>"; echo date("Y/m/d H:i:s", $time)."<br>"; ?>