1

how can I fetch this response from URL in android?

 1. //main array   
                [
                         //array in main array     
                         [
                            //object in inner array 
                            {
                                //data to be fetched here 
                                "user_id": "8035",
                                "sr_no": "MG2459",
                                "user_type": "2",
                                "name": "Allen"

                            }
                        ],
                        //2nd array in main array 
                        [     
                            {
                                "user_id": "8035",
                                "sr_no": "MG2459",
                                "user_type": "2",
                                "name": "TestName"

                            }
                        ]


                ]
duggu
  • 37,851
  • 12
  • 116
  • 113
Bhushan
  • 41
  • 5
  • Lot of tutorial available on internet for this, please search here http://stackoverflow.com/questions/13196234/simple-parse-json-from-url-on-android – Sunil Kumar Oct 30 '14 at 07:26
  • Refer this: http://stackoverflow.com/questions/17673057/how-to-parse-this-nested-json-array-in-android . Hope this may help you – Krupa Patel Oct 30 '14 at 07:30
  • possible duplicate of [Example of how to download JSON from server?](http://stackoverflow.com/questions/3578441/example-of-how-to-download-json-from-server) – JanBo Oct 30 '14 at 08:07

1 Answers1

0

try below code :-

    try {
        JSONArray ja = new JSONArray(ur string);
        for (int i = 0; i < ja.length(); i++) 
        {
            JSONArray ja1 = ja.getJSONArray(i);
            for (int j = 0; j < ja1.length(); j++) {
                JSONObject jo = ja1.getJSONObject(j);
                String user_id = jo.getString("user_id");
                String sr_no = jo.getString("sr_no");
                String user_type = jo.getString("user_type");
                String name = jo.getString("name");
            }
        }
    } catch (Exception e) {
        // TODO: handle exception
    }
duggu
  • 37,851
  • 12
  • 116
  • 113