文章出處

在使用JSONObject.fromObject的時候,出現“There is a cycle in the hierarchy”異常。
 
意思是出現了死循環,也就是Model之間有循環包含關系;
 
解決辦法:
 
使用setCycleDetectionStrategy防止自包含
 
代碼:
JsonConfig jsonConfig=new JsonConfig();
 jsonConfig.setIgnoreDefaultExcludes(false); 
  jsonConfig.setExcludes(new String[]{collection});//collection 即為移除的實體對象
  JSONObject JsonObject = JSONObject.fromObject(object, jsonConfig);
 
 
 
 
 
 
 
依賴的包: 
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy

文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()