zoukankan      html  css  js  c++  java
  • 解决FastJson循环引用的问题

    temp 本来被循环引用,运行方法报错。
    解决方法:对temp进行处理

    SerializerFeature feature = SerializerFeature.DisableCircularReferenceDetect; temp = JSONObject.parseObject(JSON.toJSONString(temp,feature));

    以下为情景复现

    public JSONObject convertQueryGroupInterface(JSONObject querygroup) {

        JSONArray group = (JSONArray) querygroup.get("treeNodes");
        JSONArray convert = new JSONArray();
        JSONObject temp = new JSONObject();
        JSONObject temp1  = new JSONObject();
        SerializerFeature feature = SerializerFeature.DisableCircularReferenceDetect;
        JSONObject result = null;
    
        for (int i = 0; i <group.size(); i++){
            temp1 = (JSONObject) group.get(i);
            if (group != null){
                temp = JSONObject.parseObject(JSON.toJSONString(temp,feature));//解决FastJson循环引用的问题
                temp.put("nodeId", temp1.get("groupid"));
                temp.put("nodeType", temp1.get("nodeType"));
                temp.put("nodeName", temp1.get("nodeName"));
                temp.put("isLeaf", false);
                temp.put("expanded", false);
                temp.put("checkStatus",temp1.get("groupstatus"));
            }
    
            convert.add(i,temp);
            System.out.println("convert内容:"+convert);
        }
    
        for (int i = 0 ; i < convert.size() ; i ++){
            result = convert.getJSONObject(i);
        }
    
        return result;
    }
    博客:https://dianedii.top/
  • 相关阅读:
    378. Kth Smallest Element in a Sorted Matrix
    295. Find Median from Data Stream
    857. Minimum Cost to Hire K Workers
    373. Find K Pairs with Smallest Sums
    767. Reorganize String
    无序列表
    有序列表
    缩写
    设计者详细信息
    强调
  • 原文地址:https://www.cnblogs.com/DianeDi/p/13417587.html
Copyright © 2011-2022 走看看