加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用JSONObject转换json数据报错:There is a cycle in the hiera

发布时间:2020-12-16 19:18:03 所属栏目:百科 来源:网络整理
导读:在使用JSONObject 转换json数据的时候 出现了 There is a cycle in the hierarchy! 的错误。 JsonConfig jsonConfig=new JsonConfig();//设置自动排除circle。jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); jsonConfig.setJsonPro

在使用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去除导致死循环的字段即可

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读