使用JSONObject转换json数据报错:There is a cycle in the hierarchy!的解决办法

在使用JSONObject 转换json数据的时候 出现了

There is a cycle in the hierarchy!的错误。

JsonConfig jsonConfig=new JsonConfig();
//设置自动排除circle。
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);  
jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
	public boolean apply(Object source,String name,Object value) {
		//去除可能导致死循环的字段名(Model类中的属性名)
		if (name.equals("tblTopics") || name.equals("tblBoards")) {
			return true;
		} else {
			return false;
		}
	}
});
//声明JSONObject对象
JSONObject jsonObject = JSONObject.fromObject(dataGridJson,jsonConfig);
//输出json数据
System.out.println("转换后的json数据为:"+jsonObject.toString());

解决办法:

使用JsonConfig去除导致死循环的字段即可

相关文章

文章浏览阅读2.4k次。最近要优化cesium里的热力图效果,浏览...
文章浏览阅读1.2w次,点赞3次,收藏19次。在 Python中读取 j...
文章浏览阅读1.4k次。首字母缩略词 API 代表应用程序编程接口...
文章浏览阅读802次,点赞10次,收藏10次。解决一个JSON反序列...
文章浏览阅读882次。Unity Json和Xml的序列化和反序列化_uni...