我試圖解析來自http://www.worldweatheronline.com JSON提要的天氣信息。這是,它的格式爲:解析JSON,陣列中的數組(Android)
{ "data" : { "current_condition" : [ { "cloudcover" : "75",
"humidity" : "100",
"observation_time" : "10:01 PM",
"precipMM" : "0.0",
"pressure" : "1015",
"temp_C" : "3",
"temp_F" : "37",
"visibility" : "4",
"weatherCode" : "143",
"weatherDesc" : [ { "value" : "Mist" } ],
"weatherIconUrl" : [ { "value" : "http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0006_mist.png" } ],
"winddir16Point" : "N",
"winddirDegree" : "360",
"windspeedKmph" : "11",
"windspeedMiles" : "7"
} ],
於是就有了current_condition JSONArray
,我已成功地從獲得的值。但是,如何從內部陣列weatherDesc
或weatherIconUrl
讀取值?
這裏是我的閱讀precipMM
,pressure
,temp_C
等代碼:
String precipMM = null;
try {
JSONObject data = json.getJSONObject("data");
JSONArray current_condition = data.getJSONArray("current_condition");
for(int i = 0; i < current_condition.length(); i++) {
precipMM = current_condition.getJSONObject(i).getString("precipMM");
}
} catch (JSONException e) {
e.printStackTrace();
}
嘿馬特,你是否能夠在沒有使用傑克遜圖書館的情況下得到這個工作。我陷入了類似的情況。 –