gpt4 book ai didi

java - 在 JSONArray 中解析 JSONArray

转载 作者:行者123 更新时间:2023-11-29 05:46:32 26 4
gpt4 key购买 nike

我正在使用 Gson用于解析 json 响应。我需要在 JsonArray 中解析 JSONArry..

我的回答是..

{
"message": "Retreive sucessfully",
"flag": true,
"data": {
"myArray1": [[{
"xyz": "1400.0",
"abc": "O",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "J",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "I",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "D",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "C",
"mnp": "leeper"
}],
[{
"xyz": "1400.0",
"abc": "M",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "L",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "G",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "F",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "A",
"mnp": "leeper"
}]],
"myArray2": [[{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
}],
[{
"xyz": "1400.0",
"abc": "LS5",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS4",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS3",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS2",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS1",
"mnp": "leeper"
}],
[{
"xyz": "1000.0",
"abc": "19",
"mnp": "taes"
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
}],
[{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "20",
"mnp": "taes"
},
{
"xyz": "1000.0",
"abc": "6",
"mnp": "taes"
},
{
"xyz": "1000.0",
"abc": "3",
"mnp": "taes"
},
{
"xyz": "1000.0",
"abc": "2",
"mnp": "taes"
}],
[{
"xyz": "1000.0",
"abc": "notaes",
"mnp": null
},
{
"xyz": "1000.0",
"abc": "1",
"mnp": "taes"
}]]
},
"code": "99"
}

我的类(class)应该是什么?我已经这样做了...

public class MyLayout {
public String message;
public boolean flag;
public Data data;
public String commandName;
public String code;

public class Data {
public ArrayList<MyClass> myArray1 = new ArrayList<MyLayout.MyClass>();
public ArrayList<MyClass> myArray2 = new ArrayList<MyLayout.MyClass>();
}

public class MyClass {
public String abc;
public String xyz;
public String mnp;
}

}

它不起作用??

编辑

当响应如下所示时,我的 Above MyLayout 工作..但是 myArray 项目还包含 JSONArray

{
"message": "Retreive sucessfully",
"flag": true,
"data": {
"myArray1": [{
"xyz": "1400.0",
"abc": "O",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "J",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "I",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "D",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "C",
"mnp": "leeper"
}],
"myArray2": [{
"xyz": "1400.0",
"abc": "LS5",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS4",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS3",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS2",
"mnp": "leeper"
},
{
"xyz": "1400.0",
"abc": "LS1",
"mnp": "leeper"
}]
},
"code": "99"
}

最佳答案

myArray1myArray2 是数组的数组,因此您需要将 Data 修改为如下所示:

public class Data {
public List<List<MyClass>> myArray1 = ...
public List<List<MyClass>> myArray2 = ...
}

关于java - 在 JSONArray 中解析 JSONArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15690469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com