如何将JSON数组元素存储在变量中?

时间:2016-04-25 10:52:01

标签: android

这是我的json数组,其中包含子数组。现在我想以安排的方式在android中存储这个子数组的数据。就像第一次记录另一个,等等。我怎么能这样做?

{
    "result": [
        ["", "", "2016-04-22", "", "", "problems since last 5 days", "replace piping", "0", null],
        ["Elec4820", "", "2016-04-25", "", "", "jsjshdjdjjcncnc", "hdjdhdhfbbff", "0", null],
        ["Elec7558", "", "2016-04-25", "", "", "jsjshdjdjjcncnc", "hdjdhdhfbbff", "0", null],
        ["Gara8118", "11827", "2016-03-13", "Completed", "nknm", "too much garbage near front gate causing an unbearable stink.", "garbage ", "0", null],
        ["Nois6091", "17061", "2016-03-11", "Assigned", "Committee Member has been assigned to solve this problem", "too much noise caused by construction carried out by....ccd . .dvdv efv \r\nvvevv ", "cdhvdhb bbcsjc cincs nenvnjk \r\nvndjkn n cnicjisk m \r\niejnivn vvnveivnievnj invjievivn \r\nvienvncn", "1", null],
        ["Wate6487", "14371", "2016-03-14", "In-Progress", "gyghbn", "fegrtb fbvrv ", "ss", "1", null]
    ]
}

2 个答案:

答案 0 :(得分:0)

您的模型类必须是这样的:

public class Example {

@SerializedName("result")
@Expose
private List<List<String>> result = new ArrayList<List<String>>();

/**
* 
* @return
* The result
*/
public List<List<String>> getResult() {
return result;
}

/**
* 
* @param result
* The result
*/
public void setResult(List<List<String>> result) {
this.result = result;
}

}

之后,请阅读gson的文档来执行此操作:https://github.com/google/gson

答案 1 :(得分:0)

解析json循环通过子数组并添加到模型

中声明的hashset