我有一个Jsonobject包含一些在转换为Jsonobject之前是Arraylist的值
[{"id":4,"name":"shirt","attributeName":["size"],"attributeValue":["6-7"],"attributeStock":["3"]}]
如何获取attributeName& attributeValue& attributeStock喜欢Arraylist
答案 0 :(得分:0)
我通过这个代码来解决它(jsonFavorites是一个包含几个jsonobject的字符串,与我在问题[{},{},{}中发布的相同)
try
{
JSONArray jsonArray=new JSONArray(jsonFavorites);
for (int i=0; i<jsonArray.length();i++)
{
JSONObject object=jsonArray.getJSONObject(i);
int id=object.getInt("id");
String name=object.getString("name");
JSONArray Namearray=object.getJSONArray("attributeName");
JSONArray Valuearray=object.getJSONArray("attributevalue");
JSONArray Stockarray=object.getJSONArray("attributeStock");
ArrayList<String> attributeName=new ArrayList<>();
ArrayList<String> attributevalue=new ArrayList<>();
ArrayList<String> attributeStock=new ArrayList<>();
for (intj=0; j<Namearray.length();j++)
{
attributeName.add(Namearray.getString(j));
attributevalue.add(Valuearray.getString(j));
attributeStock.add(Stockarray.getString(j));
}
}
}catch (Exception e){}