【发布时间】:2014-05-19 08:26:45
【问题描述】:
在结果字符串中,我有我正在解析的全部数据,我需要在值中打印当前条件。
current_condition": [ {"cloudcover": "75", "humidity": "71", "observation_time": "06:55 AM", "precipMM": "0.6", "pressure": "1009", "temp_C": "32", "temp_F": "90", "visibility": "10", "weatherCode": "116", "weatherDesc": [ {"value": "Partly Cloudy" } ], "weatherIconUrl": [ {"value": "http:\/\/cdn.worldweatheronline.net\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png" } ], "winddir16Point": "S", "winddirDegree": "170", "windspeedKmph": "9", "windspeedMiles": "6" } ]
这是我的 json 数组,这里我需要 cloudcover,weatherDescarrays 值,我如何打印这些值。
我在这里做的是
JSONParser parser = new JSONParser();
Object obj1 = parser.parse(Result);
JSONObject jobj = (JSONObject) obj1;
JSONObject dataResult = (JSONObject) jobj.get("data");
JSONArray current_condition = (JSONArray) dataResult.get("current_condition");
//out.println(current_condition);
for (int i = 0; i < current_condition.size(); i++) {
}
在for循环中如何重复和打印值,谁能帮助我,提前谢谢。
【问题讨论】:
-
您的输入不是有效的 JSON。在jsonlint.com进行测试
-
{ “数据”:{ “current_condition”:[ {“cloudcover”:“75”,“湿度”:“71”,“observation_time”:“06:55 AM”,“precipMM” :“0.6”,“压力”:“1009”,“temp_C”:“32”,“temp_F”:“90”,“能见度”:“10”,“weatherCode”:“116”,“weatherDesc”:[ {“值”:“部分多云”}],“weatherIconUrl”:[{“值”:“http:\/\/cdn.worldweatheronline.net\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png”}],“ winddir16Point”:“S”,“winddirDegree”:“170”,“windspeedKmph”:“9”,“windspeedMiles”:“6”}]}}
-
您使用哪个库来解析这些数据?
-
请编辑您的问题。不要将 JSON 放入评论中。