问题描述:

I'm trying get from data of JSON. But I can't. Help me.

I get JSON array from server and parsed JSON objects like following:

public ArrayList<ArrayList<Object>> parseAllTable(JSONObject object) {

ArrayList<ArrayList<Object>> arrayList = new ArrayList<ArrayList<Object>>();

try {

JSONArray jsonArray = object.getJSONArray("Value").getJSONArray(1);

JSONObject jsonObj = null;

for (int i = 0; i < jsonArray.length(); i++) {

jsonObj = jsonArray.getJSONObject(i);

Iterator<String> iter = jsonObj.keys();

ArrayList<Object> tmpList = new ArrayList<Object>();

while(iter.hasNext())

tmpList.add(iter.next());

arrayList.add(tmpList);

}

} catch (JSONException e) {

// TODO Auto-generated catch block

Log.d("JSONParser => parseAllTable", e.getMessage());

}

return arrayList;

}

Like JSON Data:

{

"Successful": true,

"Value": {

"CoolerType": [

{

"CoolerTypeId": 1,

"CoolerTypeName": "CVC-360D",

"description": ""

},

{

"CoolerTypeId": 2,

"CoolerTypeName": "CVC-360D-2",

"description": ""

}

],

"PartsType": [

{

"parttypeid": 1,

"parttypename": "Гэрэл"

},

{

"parttypeid": 2,

"parttypename": "Гэрэлт самбар"

}

]

}

}

网友答案:

Here:

JSONArray jsonArray = object.getJSONArray("Value").getJSONArray(1);

Value is JSONObject of JSONArray's instead of JSONArray. so get Value JSONObject from object :

JSONArray jsonArray = object.getJSONObject("Value").getJSONArray(1);
相关阅读:
Top