我具有来自Web服务的以下JSON字符串,并且正在尝试将其转换为 JSONarray
JSONarray
{ "locations": [ { "lat": "23.053", "long": "72.629", "location": "ABC", "address": "DEF", "city": "Ahmedabad", "state": "Gujrat", "phonenumber": "1234567" }, { "lat": "23.053", "long": "72.629", "location": "ABC", "address": "DEF", "city": "Ahmedabad", "state": "Gujrat", "phonenumber": "1234567" }, { "lat": "23.053", "long": "72.629", "location": "ABC", "address": "DEF", "city": "Ahmedabad", "state": "Gujrat", "phonenumber": "1234567" }, { "lat": "23.053", "long": "72.629", "location": "ABC", "address": "DEF", "city": "Ahmedabad", "state": "Gujrat", "phonenumber": "1234567" }, { "lat": "23.053", "long": "72.629", "location": "ABC", "address": "DEF", "city": "Ahmedabad", "state": "Gujrat", "phonenumber": "1234567" } ] }
我String在线上对此进行了验证,这似乎是正确的。现在我在android开发中使用以下代码来利用
String
JSONArray jsonArray = new JSONArray(readlocationFeed);
这会引发异常和类型不匹配的异常。
在这里,您将获得JSONObject,因此请更改以下行:
具有以下内容:
JSONObject jsnobject = new JSONObject(readlocationFeed);
之后
JSONArray jsonArray = jsnobject.getJSONArray("locations"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject explrObject = jsonArray.getJSONObject(i); }