Java 如何在JSONObject中获取没有名称的JSONArray

Java 如何在JSONObject中获取没有名称的JSONArray,java,arrays,json,object,Java,Arrays,Json,Object,我想在每个数组索引的帮助下得到下面三个JSONArray 我的JSON: { [ { "id": 3429, "name": "Mass Effect: Andromeda", "prix": 100, "description": "The newest Mass Effect instalement", "quantiteDisponible": 400, "image": "https://res.clo

我想在每个数组索引的帮助下得到下面三个JSONArray 我的JSON:

 {
  [
    {
      "id": 3429,
      "name": "Mass Effect: Andromeda",
      "prix": 100,
      "description": "The newest Mass Effect instalement",
      "quantiteDisponible": 400,
      "image": "https://res.cloudinary.com/igdb/image/upload/t_screenshot_big/xtn9vhiek0kdpetibmvw.webp"
    },
    {
      "id": 3430,
      "name": "Halo 5: Guardians",
      "prix": 10,
      "description": "Not the best Halo",
      "quantiteDisponible": 420,
      "image": "https://res.cloudinary.com/igdb/image/upload/t_cover_big/rzjnrhuv5rozj52g9aq3.webp"
    }
  ],
  [
    {
      "id": 3431,
      "name": "Bloodbonrne",
      "prix": 20,
      "description": "Better than you",
      "quantiteDisponible": 612,
      "image": "https://res.cloudinary.com/igdb/image/upload/t_cover_big/fivw1ogfjw266t72kcn2.webp"
    },
    {
      "id": 3432,
      "name": "Dark Souls 3",
      "prix": 60,
      "description": "Prepare to die",
      "quantiteDisponible": 604,
      "image": "https://res.cloudinary.com/igdb/image/upload/t_cover_big/ofu6ewg0tzdt5vmzcj9q.webp"
    }
  ],
  [
    {
      "id": 3433,
      "name": "Mario Sunshine",
      "prix": 40,
      "description": "Mario Sunshine best Mario Game",
      "quantiteDisponible": 11,
      "image": "https://res.cloudinary.com/igdb/image/upload/t_cover_big/ok5aq7j375uaxp59zr2g.webp"
    },
    {
      "id": 3434,
      "name": "Outlaw Golf",
      "prix": 60,
      "description": "Outlaw Golf is back with a bang!",
      "quantiteDisponible": 10,
      "image": "https://res.cloudinary.com/igdb/image/upload/t_cover_big/cxgtamh2r6z7tezfs1og.webp"
    }
  ]
}
我不知道这是否可能,非常感谢您的帮助 首先,我读取JSON并将其存储到变量中:

JSONObject object = new JSONObject(JsonText);
System.out.println(object.length());
System.out.println返回3,因此它知道我们讨论的是3个JSON数组

这就是我尝试获取数组的方法

for (int i = 0; i < object.length(); i++){
        JSONArray array = object.getJSONArray(HELP);

}
for(int i=0;i
您必须传递i的值。但是object.getJSONArray()只接受字符串,所以可以这样使用

    JSONObject obj=new JSONObject(JsonText);
    for(int i=0;i<obj.length();i++){

        try {
            JSONArray jsonArray=obj.getJSONArray(String.valueOf(i));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
JSONObject obj=新的JSONObject(JsonText);

对于(inti=0;i您可以尝试此代码段

for (int i = 0; i < getArray.length(); i++) {
        JSONObject objects = getArray.getJSONObject(i);
        Iterator key = objects.keys();
        while (key.hasNext()) {
            String k = key.next().toString();
            System.out.println("Key : " + k + ", value : "
                    + objects.getString(k));
        }
        // System.out.println(objects.toString());
        System.out.println("-----------");

    }
for(int i=0;i
您使用的是哪个JSON库?您尝试过使用“0”(或“1”或“2”)作为名称吗?为什么顶级JSONArray还没有?
{[]}
真的是有效的JSON吗?我只想要一个动态JSON,所以在代码中我将添加一个新类别(在这种情况下是一个新控制台).就像我已经有了Xbox、PS4和Wii一样,在我的代码中,我将创建3DS,并将其作为一个数组添加到一堆JSONObject中