无法解析json - org.json.JSON.typeMismatch

时间:2014-02-19 20:09:44

标签: android json

我在尝试解析以下json时遇到JSONException。 https://dl.dropboxusercontent.com/u/22928439/10.json

JSONArray json = new JSONArray(data);

data是json文件中的完整字符串。

我无法弄清楚原因。

1 个答案:

答案 0 :(得分:1)

好吧,它不是JSONArray格式,而是JSONObject,所以你应该尝试以下方法:

JSONObject json = new JSONObject(data);

JSONArray的例子:

[
     { "type": "home", "number": "212 555-1234" },
     { "type": "fax", "number": "646 555-4567" }
]

JSONObject的示例:

{
     "firstName": "John", "lastName": "Smith", "age": 25,
     "address" : {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": "10021"
     },
     "phoneNumber": [
         { "type": "home", "number": "212 555-1234" },
         { "type": "fax", "number": "646 555-4567" }
     ]
}