zoukankan      html  css  js  c++  java
  • 无key值的json数组解析

    [
        [
            {
                "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);
    }
  • 相关阅读:
    图解测试之稳定性-如何开始稳定性测试
    系统稳定性保障
    系统稳定性评测
    分布式架构的架构稳定性
    app测试--稳定性测试
    服务器稳定性测试方法汇总
    服务端稳定性测试
    发票问题
    android x86 固件定制
    Nim游戏博弈(收集完全版)
  • 原文地址:https://www.cnblogs.com/kim-liu/p/7704150.html
Copyright © 2011-2022 走看看