使用JSONObject.fromObject的时候出现“There is a cycle in the hierarchy”异常 的解决办法
2016-04-25 09:17
721 查看
在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常。
意思是出现了死循环,也就是Model之间有循环包含关系;
解决办法:
使用setCycleDetectionStrategy防止自包含
代码:
依赖的包:
意思是出现了死循环,也就是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 |
相关文章推荐
- iOS开发系列—Objective-C之Foundation框架
- json字符串转换为JSONObject和JSONArray .
- iOS开发系列--Objective-C之KVC、KVO
- Spring MVC 解决 Could not write JSON: No serializer found for class java.lang.Object
- iOS开发系列--Objective-C之类和对象
- iOS开发系列—Objective-C之基础概览
- 浅谈Swift和Objective-C之间的那点事。。。
- 以下介绍的三种方法属于Object
- 用EL表达式获取List<Map<String,Object>>里面的值
- Delphi_09_Delphi_Object_Pascal_面向对象编程
- pip安装模块警告InsecurePlatformWarning: A true SSLContext object is not available.
- iOS-Effective Objective-C 2.0 读书笔记(二)
- Objective-C语法之NSArray和NSMutableArray
- Objective-C学习
- 快速上手之 Objective-C 中的 Runtime
- Page Object 模式编写UiAutomator脚本
- u3d脚本入门一,动态创建GameObject(原创)
- DeepLearning论文笔记(一):What is the Best Muti-Stage Architecture for object Recognition
- Cannot update object that was never inserted
- Foundation => Objective-C _ Part1