我在getjson调用中有一个for循环,但循环不起作用......
var woeid = '455827';
var yql = encodeURIComponent('select * from weather.forecast where woeid = "' + woeid + '"and u="c"')
$$.getJSON('https://query.yahooapis.com/v1/public/yql?q='+ yql + '&format=json', function (data) {
var forecast = data.query.results.channel.item.forecast;
//Forecast
for(var i=0;i<=forecast.length;i++){
//Get
code = data.query.results.channel.item.forecast[i].code;
data = data.query.results.channel.item.forecast[i].date;
weekday = data.query.results.channel.item.forecast[i].day;
max = data.query.results.channel.item.forecast[i].high;
min = data.query.results.channel.item.forecast[i].low;
console.log(max);
}
});},3000)
循环不起作用,console.log什么都没显示......出了什么问题?
由于
答案 0 :(得分:0)
解决:我将我的代码更改为:
而不是
var forecast = data.query.results.channel.item.forecast;
for(var i=0;i<=forecast.length;i++){
//Get
code = data.query.results.channel.item.forecast[i].code;
data = data.query.results.channel.item.forecast[i].date;
weekday = data.query.results.channel.item.forecast[i].day;
max = data.query.results.channel.item.forecast[i].high;
min = data.query.results.channel.item.forecast[i].low;
}
我做了
var forecast = data.query.results.channel.item.forecast;
for(var i=0;i<=forecast.length;i++){
//Pega
code = forecast[i].code;
data = forecast[i].date;
weekday = forecast[i].day;
max = forecast[i].high;
min = forecast[i].low;
}
虽然我相信第一个代码应该可行,但第二个代码对我来说就像魅力一样
谢谢大家:)