Devendra Chavan
Devendra Chavan

Reputation: 13

Parse Json Array Inside Multiple Json Array with android

How do I make a JSON object with multiple arrays?

I've never used JSON before so I'm not familiar with its syntax.
Problem is that i don't know what wold be next array name. It is possible to parse data from all arrays without name of it and without changing structure of it? How do I parse multiple JSON arrays using Volley?

[
  [
    {
      "project_id": "1",
      "club_id": "98",
      "project_name": "Testing Project",
      "project_date": "2019-04-18",
      "project_venue": "ADT Office",
      "expense": "1000000",
      "benificiaries": "10",
      "description": "Testing Project can be anything",
      "approved": "Pending",
      "status": "active",
      "imagepath1": "project-images/Ahmednagar_Central/9426693-1555579879-1-98.png",
      "imagepath2": "project-images/Ahmednagar_Central/9426693-1555579879-2-98.png",
      "public_image": "yes",
      "public_image1": "project-images/Ahmednagar_Central/9426693-1555579879-3-98.png",
      "public_image2": "project-images/Ahmednagar_Central/9426693-1555579879-4-98.png",
      "year": "2019-20",
      "resent_reason": "",
      "timestamp": "2019-04-18",
      "update_timestamp": "2019-04-18"
    }
  ],
  [
    {
      "avenue_name": "Club Administration"
    },
    {
      "avenue_name": "The Rotary Foundation"
    },
    {
      "avenue_name": "Community Development"
    },
    {
      "avenue_name": "District Emphasis"
    }
  ],
  [
    {
      "nonrtn_contribution_id": "1",
      "project_id": "1",
      "no_of_rotractors": "10",
      "rotractors_work_hours_": "10",
      "no_of_anns": "3",
      "anns_work_hours": "3",
      "no_of_annets": "23",
      "annets_work_hours": "15",
      "no_of_nonrtn": "10",
      "nonrtn_work_hours": "19",
      "status": "active",
      "timestamp": "2019-04-18"
    }
  ],
  [
    {
      "work_hours": "6",
      "first_name": "Rajesh",
      "last_name": "Bansal"
    },
    {
      "work_hours": "5",
      "first_name": "Narendra",
      "last_name": "Chordiya"
    },
    {
      "work_hours": "8",
      "first_name": "Shrikrishna",
      "last_name": "Joshi"
    },
    {
      "work_hours": "2",
      "first_name": "Shirish",
      "last_name": "Rayate"
    },
    {
      "work_hours": "1",
      "first_name": "Ganesh",
      "last_name": "Shah"
    },
    {
      "work_hours": "3",
      "first_name": "Pramod",
      "last_name": "Shah"
    }
  ]
]

Upvotes: 0

Views: 1236

Answers (1)

oligan
oligan

Reputation: 634

Your JSON String is composed of an array , which contains arrays, which contain objects. so

// parse json to an array
JSONArray array = new JSONArray(jsonString);
// loop through that array and get nested arrays
for (int i = 0; i < array.length(); i++) {
     JSONArray subArray = array.getJSONArray(i);
     // loop trhough those nested arrays to retrieve the objects
     for (int j = 0; j < subArray.length(); j++) {
           JSONObject obj = subArray.getJsonObject(j);
           // parse the object properties...

     }
}

Upvotes: 1

Related Questions