在使用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

相关文章:

  • 2021-07-15
  • 2021-12-19
  • 2021-09-17
  • 2022-12-23
  • 2021-12-19
  • 2017-11-23
猜你喜欢
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
相关资源
相似解决方案