`
mybwu_com
  • 浏览: 178883 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

There is a cycle in the hierarchy

 
阅读更多

在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常。

意思是出现了死循环,也就是Model之间有循环包含关系;

解决办法:

使用setCycleDetectionStrategy防止自包含

代码:

JsonConfig jsonConfig = new JsonConfig();

jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);

JSONObject json =JSONObject.fromObject(model, jsonConfig);

result = json.toString();

依赖的包:

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

参考网页:

http://www.cnblogs.com/az19870227/archive/2011/09/19/2180993.html


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics