2013-07-15 3 views
2

Я пытаюсь получить почасовой прогноз температуры на определенный час дня от API Wunderground для исследовательского проекта:hourly_forecast из 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; 
     } 

Тем не менее, я постоянно получаю неправильный temp.english для six_hour_forecast.

Так близко - что мне не хватает?

ответ

0

Это сделал:

// Get the forecast 6 hour temp 
$.each(parsed_json['hourly_forecast'], function(index, value) { 
    if(value['FCTTIME']['hour']==sunrise_hour*1 + 6 && value['FCTTIME']['mday']==window.current_day) { 
    window.six_hour_forecast = value.temp.english; 
    } 
}); // end each 
Смежные вопросы