我正在尝试从研究项目的 Wunderground API 获取一天中特定小时的每小时预报温度:
这是 JSON 的示例: http ://api.wunderground.com/api/[key]/geolookup/astronomy/forecast/history_/hourly/conditions/q/mo/columbia.json
具体部分如下所示:
"hourly_forecast": [
{
"FCTTIME": {
"hour": "17","hour_padded": "17","min": "00","sec": "0","year": "2013","mon": "7","mon_padded": "07","mon_abbrev": "Jul","mday": "15","mday_padded": "15","yday": "195","isdst": "1","epoch": "1373925600","pretty": "5:00 PM CDT on July 15, 2013","civil": "5:00 PM","month_name": "July","month_name_abbrev": "Jul","weekday_name": "Monday","weekday_name_night": "Monday Night","weekday_name_abbrev": "Mon","weekday_name_unlang": "Monday","weekday_name_night_unlang": "Monday Night","ampm": "PM","tz": "","age": ""
},
"temp": {"english": "86", "metric": "30"},
"dewpoint": {"english": "71", "metric": "22"},
"condition": "Thunderstorm",
"icon": "tstorms",
"icon_url":"http://icons-ak.wxug.com/i/c/k/tstorms.gif",
"fctcode": "15",
"sky": "66",
"wspd": {"english": "10", "metric": "16"},
"wdir": {"dir": "ESE", "degrees": "119"},
"wx": "Scattered Thunderstorms , Scattered Light Rain Showers",
"uvi": "3",
"humidity": "60",
"windchill": {"english": "-9998", "metric": "-9998"},
"heatindex": {"english": "91", "metric": "33"},
"feelslike": {"english": "91", "metric": "33"},
"qpf": {"english": "", "metric": ""},
"snow": {"english": "", "metric": ""},
"pop": "30",
"mslp": {"english": "30.14", "metric": "1020"}
}
,
我得到这样的JSON:
$.ajax({
url : "http://api.wunderground.com/api/[key]/geolookup/forecast/hourly/history_/astronomy/conditions/q/"+lat+","+lon+".json",
dataType : "jsonp",
success : function(parsed_json) {
然后我尝试像这样运行每小时预测(通常 mday 和 hour 被替换为包含今天日期和特定小时的变量,但为了进行故障排除,我将这些数字放入)。
// get the forecast
$.each( parsed_json['hourly_forecast'], function( i, value ) {
if( value.FCTTIME.mday == 15 && value.FCTTIME.hour == 19) {
six_hour_forecast = value.temp.english;
}
但是,我总是为 Six_hour_forecast 得到错误的 temp.english。
如此接近——我错过了什么?