我试图解析来自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();
}
嘿马特,你是否能够在没有使用杰克逊图书馆的情况下得到这个工作。我陷入了类似的情况。 –