使用android解析多个Json数组内的Json数组

德文德拉·查万

如何使用多个数组制作 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"
    }
  ]
]
寡头

您的 JSON String 由一个 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...

     }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章