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/
  • 相关阅读:
    Django之查询总结
    cookie与session
    Django之跨表查询及添加记录
    Django框架之单表操作
    Django框架之ORM(数据库)操作
    Django框架之模板基础,静态文件配置
    Django框架之模板语法(重要!)
    Django基础篇
    Django-MTV
    [BZOJ 1034] [ZJOI2008] 泡泡堂BNB 【贪心】
  • 原文地址:https://www.cnblogs.com/DianeDi/p/13417587.html
Copyright © 2011-2022 走看看