地下天气每小时1天预报 [英] Weather Underground Hourly 1-day Forecast
问题描述
我正在使用Weather Underground API,使用json和解析变量.我有一个问题.我无法弄清楚如何显示每小时1天的天气预报,如下所示:
I am taking the Weather Underground API, using json and parsing variables. I have an issue. I cannot figure out how to display the hourly 1-day forecast like something like so:
2015年1月25日美国东部时间上午11点的小时预测
Hourly Forecast 11AM EST on January 25, 2015
60F 55F大部分多云
60F 55F Mostly Cloudy
16 MPH NNW 41
16 MPH NNW 41
60F
这将解释更多的 https://www.youtube.com/在3:30时间观看?v = S6A138NBuyk& feature = youtu.be .
这是我到目前为止的代码:
Here is the code I have so far:
$.ajax({
url: "http://api.wunderground.com/api/72df18b7f213607b/hourly/q/CO/Alamosa.json",
dataType : "jsonp",
success : function(parsed_json) {
var hourly = parsed_json['hourly_forecast']['FCTTIME'];
for(index in hourly)
var newHourly = 'Today is' + hourly_forecast[index]['weekday_name'];
$(".hourFore").append(newHourly);
}
});
Here is the weather underground api doc for hourly: http://www.wunderground.com/weather/api/d/docs?d=data/hourly&MR=1
推荐答案
hourly_forecast
是一个对象数组,每个对象中都包含FCTTIME
.
hourly_forecast
is an array of objects that contain FCTTIME
in each.
我不会为您解析它的所有各个组成部分,但是您可以在此处看到访问它的一般方法:
I'm not going to try and parse all the various components of it for you but you can see the general approach to accessing it here:
$.getJSON('http://api.wunderground.com/api/72df18b7f213607b/hourly/q/CO/Alamosa.json',function(resp){
$.each(resp.hourly_forecast, function(){
logTime(this.FCTTIME);
});
});
function logTime( obj){
$('body').append(obj.weekday_name + ' '+ obj.civil +'<br>');
console.log(obj);
}
这篇关于地下天气每小时1天预报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!