Android parse this JSON - how? [closed]
my json:
[
{
"all": {
"dates": [
{
"date": "2011-01-18",
"name": "asd"
},
{
"date": "2011-02-19",
开发者_开发技巧 "name": "ddd"
},
{
"date": "2011-11-21",
"name": "eee"
}
],
"dep": [
{
"code": "BBB",
"name": "BUD"
}
],
"citys": [
{
"id": "2163",
"name": "ASD"
},
{
"id": "2369",
"name": "EFG"
},
...
my code
JSONArray json = new JSONArray(s); //json string
for(int i=0;i<json.length();i++){
String settings = json.getJSONObject(i).getString("all");
JSONArray jsonarray = new JSONArray(settings);
for (int j=0; j<jsonarray.length();j++){
String dates = jsonarray.getJSONObject(j).getString("dates");
JSONArray jsonarray2 = new JSONArray(dates);
for (int k=0; k<jsonarray2.length();k++){
String date = jsonarray2.getJSONObject(k).getString("date");
Log.e("date", date);
}
..
.
07-19 09:52:31.356: ERROR/ex(19038): org.json.JSONException: Value {"citys":[{"id":"2163","...
How can I parse this file correctly?
Thanks, Leslie
json.getJSONObject(i).getString("all");
JSONArray jsonarray = new JSONArray(settings);
'all' is a JSONObject, not a JSONArray, so get JSONObject and get JSONArrays dates,dep,citys.
Can directly get json.getJSONObject(i).getJSONObject("all");
or getJSONObject from String,
JSONObject jsonobj = new JSONObject(settings);
精彩评论