0

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

1
  • Your error itself told that JSONObject cannot be converted to JSONArray. your "Table" data is JSONObject type. Commented Mar 2, 2015 at 10:16

1 Answer 1

2

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

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

JSONArray data = list.getJSONArray("Columns");
Sign up to request clarification or add additional context in comments.

1 Comment

getJSONObject(i) in JSONObject cannot be applied

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.