用Android解析多个Json数组内的Json数组

时间:2019-05-10 09:43:39

标签: android json android-volley

如何制作具有多个数组的JSON对象?

我以前从未使用过JSON,所以我对它的语法不熟悉。
 问题是我不知道下一个数组名称是什么。是否可以解析所有数组中的数据而无需其名称和不更改其结构?如何使用Volley解析多个JSON数组?

[
  [
    {
      "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"
    }
  ]
]

1 个答案:

答案 0 :(得分:1)

您的JSON字符串由array组成,该array包含包含对象的数组。

// 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...

     }
}