WU api を使用して、1 時間ごとの気象データを取得します。API は、1 時間ごとに複数の値を持つ Json を返します。必要なものを照会したいと思います。
ジョンソン:
{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"hourly": 1
}
}
,
"hourly_forecast": [
{
"FCTTIME": {
"hour": "13","hour_padded": "13","min": "00","min_unpadded": "0","sec": "0","year": "2015","mon": "12","mon_padded": "12","mon_abbrev": "Dec","mday": "30","mday_padded": "30","yday": "363","isdst": "0","epoch": "1451509200","pretty": "1:00 PM PST on December 30, 2015","civil": "1:00 PM","month_name": "December","month_name_abbrev": "Dec","weekday_name": "Wednesday","weekday_name_night": "Wednesday Night","weekday_name_abbrev": "Wed","weekday_name_unlang": "Wednesday","weekday_name_night_unlang": "Wednesday Night","ampm": "PM","tz": "","age": "","UTCDATE": ""
},
"temp": {"english": "60", "metric": "16"},
"dewpoint": {"english": "34", "metric": "1"},
"condition": "Clear",
"icon": "clear"
}
,
{
"FCTTIME": {
...
}
,
"FCTTIME": {
...
},
... more FCTTIME
]
}
hourly_forecast
これは配列として取得する私のコードです:
$jsonRequest = file_get_contents("weather.json");
$data = json_decode($jsonRequest, true);
$array = @$data['hourly_forecast'];
temp
とcondition
を取得する必要があり"hour": "13"
ます。したがって、PHP は次のように出力します。The weather is $condition with $temp degree.