【发布时间】:2013-08-19 23:31:57
【问题描述】:
我无法解析这个特定的 JSONObject,
这是对象:
{"status":1,"dds":{"id":1,"name":"DDS1","description":"This is DDS 1","children":[{"id":2,"order":1,"type":1,"children":[{"id":3,"order":1,"type":3,"children":[]},{"id":4,"order":2,"type":2,"children":[]}]}]}}
该对象存储在我的名为 result 的变量中,这是我解析它的代码:
JSONObject jsonObj = null;
JSONArray jsonArr = null;
try {
jsonObj = new JSONObject(result);
jsonArr = jsonObj.getJSONArray("dds");
} catch (JSONException e) {
e.printStackTrace();
}
它给了我这个错误:
org.json.JSONException: Value {"id":1,"children":[{"type":1,"order":1,"id":2,"children":[{"type":3,"order":1,"id":3,"children":[]},{"type":2,"order":2,"id":4,"children":[]}]}],"description":"This is DDS 1","name":"DDS1"} at dds of type org.json.JSONObject cannot be converted to JSONArray
我正在尝试将其分解为子数组。我哪里错了?
@爱先生
这是我对您的代码的输出
【问题讨论】:
-
我建议你使用 GSON 库进行 JSON 解析
-
那会有什么不同?它会在安卓上运行吗?
-
@RiteshGune,我知道两者之间的区别。我现在才注意到服务器在这种情况下返回了一个对象,而我在所有其他情况下都返回了一个数组。但是我的问题现在是通过“孩子”将我的对象拆分为一个数组,但这给了我一个错误,我不明白为什么,我检查了拼写等。
-
Zapnologica,无意冒犯,只是想知道你是否知道。
标签: java json jsonobject