参考您必须使用的Wunderground API 文档:
http://api.wunderground.com/api/Your_Key/forecast/q/TN/XXX.json
在你的file_get_contents()
.
这将返回一个响应,其中包含一个forecast
对象,在该对象中,您将一周的预测作为文本(txt_forecast
对象)和仅数据版本(simpleforecast
对象):
{
"response":{
...
},
"forecast":{
"txt_forecast":{
"date":"2:00 PM PDT",
"forecastday":[
{
"period":0,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Tuesday",
"fcttext":"Partly cloudy in the morning, then clear. High of 68F. Breezy. Winds from the West at 10 to 25 mph.",
"fcttext_metric":"Partly cloudy in the morning, then clear. High of 20C. Windy. Winds from the West at 20 to 35 km/h.",
"pop":"0"
},
{
"period":1,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Tuesday Night",
"fcttext":"Mostly cloudy. Fog overnight. Low of 50F. Winds from the WSW at 5 to 15 mph.",
"fcttext_metric":"Mostly cloudy. Fog overnight. Low of 10C. Breezy. Winds from the WSW at 10 to 20 km/h.",
"pop":"0"
},
{
...
}
]
},
"simpleforecast":{
"forecastday":[
{
"date":{
"epoch":"1340776800",
"pretty":"11:00 PM PDT on June 26, 2012",
"day":26,
"month":6,
"year":2012,
"yday":177,
"hour":23,
"min":"00",
"sec":0,
"isdst":"1",
"monthname":"June",
"weekday_short":"Tue",
"weekday":"Tuesday",
"ampm":"PM",
"tz_short":"PDT",
"tz_long":"America/Los_Angeles"
},
"period":1,
"high":{
"fahrenheit":"68",
"celsius":"20"
},
"low":{
"fahrenheit":"50",
"celsius":"10"
},
"conditions":"Partly Cloudy",
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"skyicon":"mostlysunny",
"pop":0,
"qpf_allday":{
"in":0.00,
"mm":0.0
},
"qpf_day":{
"in":0.00,
"mm":0.0
},
"qpf_night":{
"in":0.00,
"mm":0.0
},
"snow_allday":{
"in":0,
"cm":0
},
"snow_day":{
"in":0,
"cm":0
},
"snow_night":{
"in":0,
"cm":0
},
"maxwind":{
"mph":21,
"kph":34,
"dir":"West",
"degrees":272
},
"avewind":{
"mph":17,
"kph":27,
"dir":"West",
"degrees":272
},
"avehumidity":72,
"maxhumidity":94,
"minhumidity":58
},
{
...
}
]
}
}
}