我想在下面我loaded10DayForcast功能得到10天預測,但我發現了以下錯誤:地下氣象預報10Day API
Cannot read property 'simpleforecast' of undefined
好像我不知道基於正確的API調用做從這個:http://www.wunderground.com/weather/api/d/docs?d=data/forecast10day
這是奇怪的,因爲我能夠得到正確顯示當前的條件。
//Get the current weather conditions
function getCurrentConditions(text) {
console.log("\n")
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if (doc.readyState == XMLHttpRequest.DONE) {
var jsonObject = eval('(' + doc.responseText + ')');
loadedCurrentConditions(jsonObject);
}
}
doc.open("GET", "http://api.wunderground.com/api/KEY/forecast/geolookup/conditions/q/"+ text + ".json");
doc.send();
}
//Get the 10 Day Forcast
function get10DayForcast(text) {
console.log("\n")
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if (doc.readyState == XMLHttpRequest.DONE) {
var jsonObject = eval('(' + doc.responseText + ')');
loaded10DayForcast(jsonObject);
}
}
doc.open("GET", "http://api.wunderground.com/api/KEY/forecast10day/q"+ text + ".json");
doc.send();
}
//Display to console
function showRequestInfo(text) {
console.log(text)
}
function loadedCurrentConditions(jsonObject)
{
showRequestInfo("Current Temp F:" + jsonObject.current_observation.temp_f);
showRequestInfo("Weather Description:" + jsonObject.current_observation.weather);
showRequestInfo("Icon:" + jsonObject.current_observation.icon);
}
function loaded10DayForcast(jsonObject)
{
showRequestInfo("Today High Temp F:" + jsonObject.forecast.simpleforecast.forecastday.Forecast[0].low.fahrenheit);
}