问题描述
||
http://weather.yahooapis.com/forecastjson?w=2295424
{
\"units\":
{\"temperature\":\"F\",\"speed\":\"mph\",\"distance\":\"mi\",\"pressure\":\"in\"},\"location\":{\"location_id\":\"INXX0075\",\"city\":\"Madras\",\"state_abbreviation\":\"*\",\"country_abbreviation\":\"IN\",\"elevation\":49,\"latitude\":13,\"longitude\":80.18000000000001},\"wind\":{\"speed\":12.00000000000000,\"direction\":\"E\"},\"atmosphere\":{\"humidity\":\"23\",\"visibility\":\"4.35\",\"pressure\":\"29.77\",\"rising\":\"steady\"},\"url\":\"http:\\/\\/weather.yahoo.com\\/forecast\\/INXX0075.html\",\"logo\":\"http:\\/\\/l.yimg.com\\/a\\/i\\/us\\/nt\\/ma\\/ma_nws-we_1.gif\",\"astronomy\":{\"sunrise\":\"06:20\",\"sunset\":\"18:19\"},\"condition\":{\"text\":\"Sunny\",\"code\":\"32\",\"image\":\"http:\\/\\/l.yimg.com\\/a\\/i\\/us\\/we\\/52\\/32.gif\",\"temperature\":93.00000000000000},\"forecast\":[{
\"day\":\"Today\",\"condition\":\"Mostly Clear\",\"high_temperature\":\"91\",\"low_temperature\":\"69\"},{\"day\":\"Tomorrow\",\"condition\":\"Partly Cloudy\",\"high_temperature\":\"90\",\"low_temperature\":\"70\"}
]}
我要显示“预测”解决方法
$.ajax({
url: \"http://weather.yahooapis.com/forecastjson?w=2295424\",dataType: \"json\",success: function(data) {
console.log( data.forecast[0].day );
}
});
在data.forecast [0] .day中,用所需的任何属性替换\“ day \”。,这应该是可行的:
console.debug(\"initYahooWeather starting\");
var urlYahooWeather = \"http://weather.yahooapis.com/forecastjson?w=2295424\";
var urlFlickr = \"http://weather.yahooapis.com/forecastjson?jsoncallback=?&w=2295424\";
jQuery.ajax({
async: false,type: \"POST\",contentType: \"application/json\",url: urlFlickr,success: function(data){
console.dir(data);
console.dir(data.forecast);
// here you have to navigate the array
},error: function(msg){
console.debug(\"error contacting JSON server side component...\");
console.debug(msg);
}
});
console.debug(\"initYahooWeather stop\");
我尝试过自己,但是使用jQuery 1.5时收到一个解析错误:我不知道为什么,代码应该可以。
马济