Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve multidimensional array using json in android [closed]

I have a multidimensional array that I want to retrieve using JSON in android. I have the following JSON Structure for this :

  [
      [
        {
          "name": "Banking",
          "data": [
            {
              "vendor_name": "SBI",
              "vendor_id": "1"
            },
            {
              "vendor_name": "ICICI",
              "vendor_id": "2"
            },
            {
              "vendor_name": "BOB",
              "vendor_id": "3"
            }
          ],
          "count": 4
        }
     ]
 ]

I want to get "name",vendor_name,vendor_id in my Strings in android. But I am not getting idea how to do this. Please let me know how to retrieve this.

like image 324
Ruchir Avatar asked Sep 15 '14 05:09

Ruchir


1 Answers

     try {
            jsonObj = new JSONObject(YourString);
        } catch (JSONException e) {
            Log.v("Error in Parser", " " + e);
        }
    try{

     String name=jsonObj.getString("name"); 
            Data = jsonObj.getJSONArray("data");
                for (int i = 0; i < Data.length(); i++) {       
                        JSONObject jsonObj2 = Data.getJSONObject(j);   
                        String vName = jsonObj2.getString("vendor_name");
                        String vId=jsonObj2.getString("vendor_id");     
                }
}catch(Exception e)
{
}
like image 80
Palash Agrawal Avatar answered Oct 05 '22 22:10

Palash Agrawal