JSONObject不是JSONObject

时间:2014-09-11 16:01:33

标签: java json

以下是我收到的JSON字符串响应。我正在使用JSON解析它。

String jsonString = "{\"a\":{\"b\":{\"c\":\"d\",\"e\":\"00\",\"f\":\"A\",\"g\":\"2\",\"h\":\"24\",\"i\":[{\"TypeFile\":\"232\",\"Request\":\"ere\",\"Thle\":\"999999\"},{\"TypeFile\":\"0720\",\"Request\":\"Y\",\"Thle\":\"999999\"}]},\"asd\":\"http://google.com/Itest\"}}";
JSONObject obj1 = new JSONObject(jsonString );
System.out.println(obj1);
//JSONObject obj = obj1.getJSONObject("a").getJSONObject("b");
//System.out.println(obj.getJSONArray("c"));
JSONObject obj2 = obj1.getJSONObject("a");
System.out.println(obj2);
JSONObject obj3 = obj2.getJSONObject("b");
System.out.println(obj3.get("e"));
System.out.println(obj2.get("asd"));
System.out.println(obj3 instanceof JSONObject);

我收到以下错误:

{"errorMsg": "JSONObject['b'] is not a JSONObject."}

是什么原因?

1 个答案:

答案 0 :(得分:0)

作为建议,你可以试试这个:

JSONArray jsonArray = obj1.getJSONArray("b"); //try to get an JSONArray
String s = jsonArray.getJSONObject(0).getString("e"); //then you can try this...