0

i have being trying to parse through a JSON data in android and am looking for a code that can take the values out.JSON data structure is as shown below:

{
    "p":
        [
            {"t1":
                [
                    {
                        "key":"value", "key1":"value1"
                    },
                    {
                        "key":"value2","key1":"value3"
                    }
                ],
             "t2":
                [
                    {
                        "key":"value", "key1":"value1"
                    },
                    {
                        "key":"value2","key1":"value3"
                    }
                ],........
            }
        ]
}

that is my JSON data that i want to parse in android and the function that parses that data should return an array of all the values in in t1,t2 onwards but the array should not be an array of nested arrays or a nested array. please help.

Stuart
  • 6,630
  • 2
  • 24
  • 40

2 Answers2

0

put your json in ,jsontopojo! it will generate model classes for you

Ashrith K S
  • 490
  • 5
  • 13
0

Try this , if you face any problem comment.

JSONObject jo=new JSONObject("YOUR JSON STRING");
JSONArray jsonArray = jo.getJSONArray("p");
JSONObject j1=jsonArray.getJSONObject(0);
  for(int j=1;j<=j1.length();j++){
    JSONArray jArr1=j1.getJSONArray("t"+j);
      for(int i=0;i<jArr1.length();i++){
        JSONObject jsonObjectList=jArr1.getJSONObject(i);
        String key=jsonObjectList.getString("key");
        String key1=jsonObjectList.getString("key1");
    }
}
Divyesh Patel
  • 2,576
  • 2
  • 15
  • 30