Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从JSONArray获取位置节和项目?_Java_Android - Fatal编程技术网

Java 如何从JSONArray获取位置节和项目?

Java 如何从JSONArray获取位置节和项目?,java,android,Java,Android,现在,我想用section创建Gridview,并执行以下操作 然后我把问题卡在了我不知道如何从JSONArray获取位置部分和项目上 我有这样的JSONArray “Team”: [ { "team_id": "16", "team_name": "3", "team_max_player": "6", "team_amount": "2", "team_member_list

现在,我想用section创建Gridview,并执行以下操作

然后我把问题卡在了我不知道如何从JSONArray获取位置部分和项目上

我有这样的JSONArray

“Team”: [
        {
          "team_id": "16",
          "team_name": "3",
          "team_max_player": "6",
          "team_amount": "2",
          "team_member_list": [
            {
              "id": "19",
              "room_id": "23",
              "user_id": "75",
              "team_id": "16",
              "detail_status": ""
            },
            {
              "id": "21",
              "room_id": "23",
              "user_id": "46",
              "team_id": "16",
              "detail_status": ""
            }
          ]
        },
        {
          "team_id": "14",
          "team_name": "1",
          "team_max_player": "1",
          "team_amount": "1",
          "team_member_list": [
            {
              "id": "20",
              "room_id": "23",
              "user_id": "40",
              "team_id": "14",
              "detail_status": ""
            }
          ]
        }
      ]
我想将团队id设置为节,团队成员列表设置为该节中的项目。 请教我怎么做


我目前在学校读12年级,有编程课、android studio、JAVA Moblie应用程序。请帮助我并为我的英语感到抱歉。

首先,您可以将JSON作为字符串加载,并使用

然后可以使用解析JSONObject中的JSON数组来检索所需的详细信息

请参阅下面的代码示例,该示例将在控制台中记录每个团队成员的id以及他们所属团队的id

    JSONObject jsonObject = new JSONObject(jsonString);
    JSONArray teams = jsonObject.getJSONArray("Team");
    for (int i = 0; i < teams.length(); i++) {
        String teamId = jsonObject.getJSONArray("Team").getJSONObject(i).getString("team_id");
        JSONArray teamMemberList = jsonObject.getJSONArray("Team").getJSONObject(i).getJSONArray("team_member_list");
        for (int j = 0; j < teamMemberList.length(); j++) {
            String teamMemberId = teamMemberList.getJSONObject(j).getString("id");
            Log.i("team", "team id: " + teamId + " team member id: " + teamMemberId);
        }
    }

如果您想了解更多关于Android中JSON解析的信息,我写了一篇更详细的文章。

谢谢,但我想获得team_id的位置,以便在方法sections中设置Section。addnew SectionEdGridRecyclServiceAdapter。Section position,team_name;若要使用Section创建Gridview,您能否共享问题中与Section相关的代码?我将代码发布在下面的注释中,请帮助我完成此操作。我在我的应用程序中停留在这个页面太多天了这能回答你的问题吗?也不清楚您不知道如何从JSONArray获取位置节和项目是什么意思-JSON数据中没有任何位置信息