public static void main(String[] args) {

        List<WeighOrderCartExtendVO> extendVOs = new ArrayList<>();
        //根据售卖类型分组

        WeighOrderCartExtendVO extendVO = new WeighOrderCartExtendVO();

        extendVO.setDishId("e04b0220006813fb");
        extendVO.setGoodsWeight(100);
        extendVO.setSellType(1);
        extendVO.setGoodsNum(10);
        extendVOs.add(extendVO);


        String extendInfo = JSON.toJSONString(extendVOs);
        JSONObject object = JSON.parseObject(extendInfo);
        // JSONArray array = JSON.parseArray(extendInfo);
        // System.out.println(JSONObject.parseObject(array.get(0).toString()));
    }

 

Exception in thread "main" com.alibaba.fastjson.JSONException: can not cast to JSONObject.
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:249)
    at com.ut.cook.weigh.order.WeighOrderService.main(WeighOrderService.java:669)
Caused by: java.lang.ClassCastException: com.alibaba.fastjson.JSONArray cannot be cast to com.alibaba.fastjson.JSONObject
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:247)
    ... 1 more

 

解决: 取出JSONArray中的数据后再解析!

GitHub 加速计划 / fastj / fastjson
3
1
下载
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
最近提交(Master分支:5 个月前 )
c942c834 - 1 年前
5bc4709b - 1 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐