1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| public class Test {
public static void main(String[] args) {
String s = "{\"error\":0,\"status\":\"success\",\"results\":[{\"currentCity\":\"青岛\",\"index\":[{\"title\":\"穿衣\",\"zs\":\"较冷\",\"tipt\":\"穿衣指数\",\"des\":\"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。\"},{\"title\":\"紫外线强度\",\"zs\":\"最弱\",\"tipt\":\"紫外线强度指数\",\"des\":\"属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。\"}],}]}";
JSONObject jsonObject = new JSONObject(stringBuilder.toString()) JSONObject jsonObject = JSONObject.fromObject(s);
int error = jsonObject.getInt("error"); System.out.println("error:" + error);
String status = jsonObject.getString("status"); System.out.println("status:" + status);
JSONArray result = jsonObject.getJSONArray("results");
for (int i = 0; i < result.size(); i++) { String currentCity = result.getJSONObject(i).getString("currentCity"); System.out.println("currentCity:" + currentCity);
JSONArray index = result.getJSONObject(i).getJSONArray("index");
for (int j = 0; j < index.size(); j++) { String title = index.getJSONObject(j).getString("title"); System.out.println("title:" + title); String zs = index.getJSONObject(j).getString("zs"); System.out.println("zs:" + zs); String tipt = index.getJSONObject(j).getString("tipt"); System.out.println("tipt:" + tipt); String des = index.getJSONObject(j).getString("des"); System.out.println("des:" + des); } } } }
|