【发布时间】:2019-03-27 09:06:10
【问题描述】:
首先我想知道json的结构是否正确,你可以在这里找到json:
http://demo8461125.mockable.io/whitemage
如果正确我想知道如何解析 "PANINI" ,是数组 "tipopietanza" 中的一个数组
JSONArray arr = response.getJSONArray("pietanze");
for (int i = 0; i < arr.length(); i++)
{
JSONArray pietanze = response.getJSONArray("PANINI");
List<Pietanze> listapietanze =new ArrayList<>(pietanze.length());
for(int j=0;j<pietanze.length();j++)
{
Pietanze tmp = new Pietanze();
tmp.setNome(pietanze.getJSONObject(j).getString("nomepietanza"));
listapietanze.add(tmp);
}
expandableListDetail.put(arr.getJSONObject(i).getString("tipopietanza"), listapietanze);
}
【问题讨论】:
-
在for循环内,JSONObject jsonChild = arr.getJSONObject(i); if(jsonChild.has("PANINI"){ JSONArray pietanze = jsonChild .getJSONArray("PANINI"); }
-
“我想知道 json 的结构是否正确” - 使用众多在线 JSON Formatters/Validators 之一。
-
@SamirMangroliya 我认为你的意思是像这样编辑codeshare.io/UbKVU 但它不起作用