Skip to content

服务器托管,北京服务器托管,服务器租用-价格及机房咨询

Menu
  • 首页
  • 关于我们
  • 新闻资讯
  • 数据中心
  • 服务器托管
  • 服务器租用
  • 机房租用
  • 支持中心
  • 解决方案
  • 联系我们
Menu

JSON解析问题:net.sf.json.JSONException: There is a cycle in the hierarchy!

Posted on 2023年5月6日 by hackdl

异常问题

net.sf.json.JSONException: There is a cycle in the hierarchy!
	at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97)
	at net.sf.json.JSONObject._fromBean(JSONObject.java:657)
	at net.sf.json.JSONObject.fromObject(JSONObject.java:172)
	at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:274)
	at net.sf.json.JSONObject._processValue(JSONObject.java:2655)
	at net.sf.json.JSONObject.processValue(JSONObject.java:2721)
	at net.sf.json.JSONObject.setInternal(JSONObject.java:2736)
	at net.sf.json.JSONObject.setValue(JSONObject.java:1424)
	at net.sf.json.JSONObject.defaultBeanProcessing(JSONObject.java:765)
	at net.sf.json.JSONObject._fromBean(JSONObject.java:699)
	at net.sf.json.JSONObject.fromObject(JSONObject.java:172)
	at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:274)
	at net.sf.json.JSONArray._processValue(JSONArray.java:2513)
	at net.sf.json.JSONArray.processValue(JSONArray.java:2538)
	at net.sf.json.JSONArray.addValue(JSONArray.java:2525)
	at net.sf.json.JSONArray._fromCollection(JSONArray.java:1056)
	at net.sf.json.JSONArray.fromObject(JSONArray.java:123)
	at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:240)
	at net.sf.json.JSONObject._processValue(JSONObject.java:2655)
	at net.sf.json.JSONObject.processValue(JSONObject.java:2721)
	at net.sf.json.JSONObject.setInternal(JSONObject.java:2736)
	at net.sf.json.JSONObject.setValue(JSONObject.java:1424)
	at net.sf.json.JSONObject.defaultBeanProcessing(JSONObject.java:765)
	at net.sf.json.JSONObject._fromBean(JSONObject.java:699)
	at net.sf.json.JSONObject.fromObject(JSONObject.java:172)
	at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:274)
	at net.sf.json.JSONArray._processValue(JSONArray.java:2513)
	at net.sf.json.JSONArray.processValue(JSONArray.java:2538)
	at net.sf.json.JSONArray.addValue(JSONArray.java:2525)
	at net.sf.json.JSONArray.element(JSONArray.java:1724)
	at net.sf.json.JSONArray.add(JSONArray.java:1249)
	at net.sf.json.JSONArray.add(JSONArray.java:1245)

原因分析

由于JSONObject内部会无限拆解你传入的对象,直到没有可拆解为止,在解析bean时,出现死循环调用,即:多个Bean之间出现了相互调用。如果你传入的对象有外键关系,或者相互引用,那么内部就会死循环,也就会抛出这个异常解决办法。例如,使用Hibernate时,查询中对象存在多表依赖关联。

解决方法

结果数据中过滤去掉bean中引起死循环调用的属性:

List list= this.baseService.find(xxx); // 结果数据list DataObject:数据对象
		
// 自定义JsonConfig用于过滤Hibernate配置文件所产生的递归数据	
JsonConfig config = new JsonConfig();
config.setExcludes(new String[]{"a","b"}); // 指定过滤哪些字段、对象
JSONArray result = JSONArray.fromObject(list, config);

服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net

Related posts:

  1. 北京服务器托管机房云服务器
  2. 重庆服务器托管品牌质量对比:选哪个?
  3. 企业租用机柜注意事项
  4. 广东虚拟服务器托管机构:高效稳定的互联网服务提供商
  5. 最近找工作时,一些杂七杂八的问题

服务器托管,北京服务器托管,服务器租用,机房机柜带宽租用

服务器托管

咨询:董先生

电话13051898268 QQ/微信93663045!

上一篇: Python程序与设计
下一篇: MySQL中timestamp和datetime,你用的对么?

最新更新

  • 管理价值
  • 【每日一题】工作计划的最低难度
  • angular-devkit 中 build-angular 包的作用
  • 使用 ABAP 代码删除指定 SAP CRM 系统里 Opportunity 订单的文本
  • 使用 SAP fiori-tools-proxy 时遇到的错误消息 – invalid version

随机推荐

  • “高效稳定:新市云服务器托管服务
  • 上海idc托管机房
  • idc机柜租用电费
  • 详解服务器托管收费价格:全面了解服务费用
  • 南京IDC服务器托管与租用服务概览

客服咨询

  • 董先生
  • 微信/QQ:93663045
  • 电话:13051898268
  • 邮箱:dongli@hhisp.com
  • 地址:北京市石景山区重聚园甲18号2层

友情链接

  • 服务器托管
  • 服务器租用
  • 机房租用托管
  • 服务器租用托管
©2023 服务器托管,北京服务器托管,服务器租用-价格及机房咨询 京ICP备13047091号-8