访问嵌套的JSON字符串数组

时间:2018-03-14 21:33:51

标签: java android json

我有一个看起来像这样的JSON对象

{"layout":[["12","21","31"],["empty","22","32"],["13","23","33"]]}

我正在尝试使用以下内容获取数组数据:

JSONObject layoutJson;
JSONArray  layoutData = layoutJson.getJSONArray();

但是我最终在

数组中输入了一个条目
[["12","21","31"],["empty","22","32"],["13","23","33"]]

如何以3个数组的形式从JSON对象中获取它?

1 个答案:

答案 0 :(得分:0)

JSONObject layoutJson;
JSONArray  layoutData = layoutJson.getJSONArray();
for (int i = 0; i < layoutData.length(); i++) {
    JSONObject firstArray = (JSONObject)layoutData.getJSONObject(i);
    // Do whatever you want with first array
    // you can loop through the first array again
}