我有這樣的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