【问题标题】:Parse Json Array Inside Multiple Json Array with android使用android解析多个Json数组内的Json数组
【发布时间】:2019-05-10 09:43:38
【问题描述】:

如何创建一个包含多个数组的 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"
    }
  ]
]

【问题讨论】:

    标签: android json android-volley


    【解决方案1】:

    您的 JSON 字符串由一个数组组成,其中包含数组,其中包含对象。所以

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      • 2013-01-11
      • 2015-03-19
      • 1970-01-01
      相关资源
      最近更新 更多