arual
arual

Reputation: 279

Android iterate array inside array

I have an json array from webservice connection. I want to iterate to an array objects that are columns of a table and data of a table. Array is like below:

"Table":{
"Columns":[
"ItemCode",
"Description",
"Value"
],
"Data":[{"itemCode": "01", "description": "data", "value": "val"]
}

I am doing:

JSONArray list = obj.getJSONArray("Table");
        for(int i = 0; i < list.length(); i++){
            JSONArray data = list.getJSONObject(i).getJSONArray("Columns");
            for(int j=0;j<data.length(); j++){
                data.getString(i);

            }
        }

But it displays:

org.json.JSONException: Valueat Table of type org.json.JSONObject cannot be converted to JSONArray

Upvotes: 0

Views: 50

Answers (1)

Bharath Mg
Bharath Mg

Reputation: 1127

Your "Table" is a JSONObject. You should be doing like,

JSONObject list = obj.getJSONObject("Table");

JSONArray data = list.getJSONArray("Columns");

Upvotes: 2

Related Questions