这是一个JSON,我从colorArray得到了结果(值),但是我无法从shapeArray获得结果。如何从shapeArray获取结果?如何获得shapeArray值?如何管理这些类型的嵌套JSON响应?如何在android中访问嵌套的JSON响应?
[
{
"colorArray":[
{
"colorName":"red",
"hexValue":"#f00"
},
{
"colorName":"green",
"hexValue":"#0f0"
},
{
"colorName":"blue",
"hexValue":"#00f"
},
{
"colorName":"cyan",
"hexValue":"#0ff"
},
{
"colorName":"magenta",
"hexValue":"#f0f"
},
{
"colorName":"yellow",
"hexValue":"#ff0"
}
]
},
{
"shapeArray":[
{
"shapeName":"circle"
},
{
"shapeName":"square"
},
{
"shapeName":"triangle"
},
{
"shapeName":"hexagon"
}
]
}
]
代码
for (int i = 0; i < jsonArray.length(); i++)
{ jsonObject = jsonArray.getJSONObject(i);
JSONArray jsonColorArray = jsonObject.getJSONArray("colorArray");
for (int j=0;j<jsonColorArray.length();j++)
{ JSONObject colorObj = jsonColorArray.getJSONObject(j);
String colorName = colorObj.getString("colorName");
String hexValue = colorObj.getString("hexValue");
}
}
我的代码:对(INT I = 0; I
suryac
你面临什么问题? –
我无法获取形状数组值。如何从Json数组获取shapeArray值? – suryac