我在尝试解析以下json时遇到JSONException。 https://dl.dropboxusercontent.com/u/22928439/10.json
JSONArray json = new JSONArray(data);
data是json文件中的完整字符串。
我无法弄清楚原因。
答案 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" }
]
}