Java 在JSONArray中解析JSONArray
我正在使用解析json响应。我需要在JsonArray中解析JSONArry 我的回答是Java 在JSONArray中解析JSONArray,java,android,json,gson,Java,Android,Json,Gson,我正在使用解析json响应。我需要在JsonArray中解析JSONArry 我的回答是 { "message": "Retreive sucessfully", "flag": true, "data": { "myArray1": [[{ "xyz": "1400.0", "abc": "O", "mnp": "leeper" }, { "xyz": "1400.0", "abc": "J
{
"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"
}
我应该上什么课?我已经这样做了
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;
}
}
myArray1
和myArray2
是数组的数组,因此需要修改Data
使其看起来像这样:
public class Data {
public List<List<MyClass>> myArray1 = ...
public List<List<MyClass>> myArray2 = ...
}
公共类数据{
公共列表myArray1=。。。
公共列表myArray2=。。。
}
问题出在哪里?你的解决方案无效?是的。。不工作…你反对使用JSON而不是Gson吗?我试图解释一下MyClass
也有JSONArray
。如何解决这个问题。它是数组中的一个数组。如果它是数组中的金橘,您将如何处理它?您需要对数组进行索引以提取金桔,然后对金桔进行操作。
public class Data {
public List<List<MyClass>> myArray1 = ...
public List<List<MyClass>> myArray2 = ...
}