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/
  • 相关阅读:
    实现系统托盘
    MDI窗体应用
    C#窗体的常用设置
    什么是UWP应用
    关于用js写缓动 动画
    关于tab栏切换的解析
    函数
    for循环
    if语句
    js
  • 原文地址:https://www.cnblogs.com/DianeDi/p/13417587.html
Copyright © 2011-2022 走看看