我有这样的JSON响应,我想walke认为它得到了天气条件,如“湿度”和“temp_C”等。我尝试了一些方法,但没有奏效。如何通过json响应?
({ "data" : { "current_condition" : [ { "cloudcover" : "50",
"humidity" : "44",
"observation_time" : "12:10 AM",
"precipMM" : "0.0",
"pressure" : "1013",
"temp_C" : "-2",
"temp_F" : "29",
"visibility" : "16",
"weatherCode" : "116",
"weatherDesc" : [ { "value" : "Partly Cloudy" } ],
"weatherIconUrl" : [ { "value" : "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0004_black_low_cloud.png" } ],
"winddir16Point" : "W",
"winddirDegree" : "280",
"windspeedKmph" : "24",
"windspeedMiles" : "15"
} ],
"request" : [ { "query" : "Rochester, United States Of America",
"type" : "City"
} ],
"weather" : [ { "date" : "2012-02-25",
"precipMM" : "2.2",
"tempMaxC" : "-1",
"tempMaxF" : "31",
"tempMinC" : "-5",
"tempMinF" : "24",
"weatherCode" : "116",
"weatherDesc" : [ { "value" : "Partly Cloudy" } ],
"weatherIconUrl" : [ { "value" : "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0002_sunny_intervals.png" } ],
"winddir16Point" : "W",
"winddirDegree" : "281",
"winddirection" : "W",
"windspeedKmph" : "54",
"windspeedMiles" : "34"
} ]
} })
我尝试这些:
$.getJSON(urlFromMyAPI, function (data) {
alert(data.current_condition.temp_C);
alert(data.temp_C);
alert(data[current_condition].temp_C);
// I also use loop
for (i = 0; i <= 3; i++) {
alert(data.current_condition[i])
}
});
};
是,在你的数据的数据,或者你是怎么贴? – Sinetheta 2012-02-26 01:14:19
不知道我收到了你的问题,但这个数据是什么来自世界天气在线API回来。 – Timmy 2012-02-26 01:19:00