簡體   English   中英

解析JSONArray中的JSONArray

[英]Parse JSONArray inside JSONArray

我正在使用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"
}

我應該上什么課? 我已經做到了

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;
}

}

它不起作用嗎?

編輯

當響應如下時,My 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 = ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM