[
[
{
"cartId": 9223,
"factoryId": 143,
"goodId": 7260,
"goodLogo": "upload/store/offlineGoods/20170907120024_635882.jpg",
"goodName": "邦尼兔子毛绒玩具可爱兔公仔玩偶",
"goodPrice": 160.0,
"goodQuantity": 1,
"goodSku": 19608,
"goodSpec": "颜色:卡其,尺寸:80cm,",
"isChecked": true
}
],
[
{
"cartId": 9211,
"factoryId": 102,
"goodId": 7193,
"goodLogo": "upload/store/offlineGoods/20170823193504_901377.jpg",
"goodName": "妮维雅 女士黑白出众爽身气雾150ml止汗干爽",
"goodPrice": 48.9,
"goodQuantity": 1,
"goodSku": 19536,
"goodSpec": "容量:150ml,",
"isChecked": true
}
],
[
{
"cartId": 9207,
"factoryId": 145,
"goodId": 7274,
"goodLogo": "upload/store/offlineGoods/20170912141647_622049.jpg",
"goodName": "阳澄湖 清水村 大闸蟹礼券C",
"goodPrice": 1909.0,
"goodQuantity": 1,
"goodSku": 19658,
"goodSpec": "型号:2598型,",
"isChecked": true
}
]
]
用HiJson格式化:
使用的是JsonArray解析:代码如下:
实体类为OnlineCart:
private ArrayList<ArrayList<OnlineCart>> onlineCartList;
try {
JSONArray jsonArray = new JSONArray(goodJson);
for (int i = 0 ;i < jsonArray.length();i++){
ArrayList<OnlineCart> interList = new ArrayList<OnlineCart>();
JSONArray jsonArray1 = jsonArray.getJSONArray(i);
for(int j= 0;j<jsonArray1.length();j++){
OnlineCart onlineCart = new OnlineCart();
JSONObject jsonObject = jsonArray1.getJSONObject(j);
onlineCart.cartId = jsonObject.getInt("cartId");
onlineCart.factoryId = jsonObject.getInt("factoryId");
onlineCart.goodId = jsonObject.getInt("goodId");
onlineCart.goodLogo = jsonObject.getString("goodLogo");
onlineCart.goodName = jsonObject.getString("goodName");
onlineCart.goodPrice = jsonObject.getDouble("goodPrice");
onlineCart.goodQuantity = jsonObject.getInt("goodQuantity");
onlineCart.goodSku = jsonObject.getInt("goodSku");
onlineCart.goodSpec = jsonObject.getString("goodSpec");
onlineCart.isChecked = jsonObject.getBoolean("isChecked");
interList.add(onlineCart);
}
onlineCartList.add(interList);
}