net.sf.json.JSONException: There is a cycle in the hierarchy!
来源:互联网 发布:淘宝链接转淘口令在线 编辑:程序博客网 时间:2024/06/11 05:22
net.sf.json.JSONException: There is a cycle in the hierarchy!
使用hibernate容易出现该问题,主要是由于pojo类属性存在级联关系。比如说类别和商品,在商品表里面有类别属性,而在类别表里面有个商品集合,这样就存在了嵌套引用的问题了,就会抛出这个异常。
解决方法:解决方法很简单,在将每个对象转为json对象的时候用setExcludes函数将级联的属性去除掉就可以了,如下面:
public String list() throws Exception {// 1.调用service查询类别数据List<Category> list = categoryService.getCategoryList();System.out.println("666666666666"+list);// 2.将list转化为json数据JsonConfig jsonConfig=new JsonConfig(); jsonConfig.setExcludes(new String[]{"products"});//去除级联关系 String json=JSONArray.fromObject(list, jsonConfig).toString();// 3.将json发送给浏览器ServletActionContext.getResponse().setContentType("application/json;charset=utf-8");ServletActionContext.getResponse().getWriter().write(json);return null;//告诉struts2不需要进行结果处理}
使用json取值一直都取不到,这个问题纠结了快一天,查了网上资料,对比自己遇到的问题,最后终于解决了,记录下来
阅读全文
0 0
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- json中net.sf.json.JSONException: There is a cycle in the hierarchy!的解决
- Json解析时出现net.sf.json.JSONException: There is a cycle in the hierarchy!42
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy异常,解决方法
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决方法
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案
- net.sf.json.JSONException: There is a cycle in the hierarchy
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy! 异常
- ztree,在树节点展出现滚动条后,选中一个节点的背景色宽度不够长问题
- 采集rtsp流摄像头到浏览器实时播放方案
- The program '[1052] InfoManager.vshost.exe: Program Trace' has exited with code 0 (0x0).
- 浅析递归算法
- servlet+easyui显示
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- js关于arguments和参数名称重复的问题
- 多图上传--FormData表单&Java,SSM
- 关于Listview和Checkbox控件嵌套出现的各种问题
- 一周 Go World 新鲜事[Asta 优选]
- 转载:CSDN 无鞋童鞋-------Linux下gcc/g++、make和cmake的区别
- git上找不到远程分支,直接切换报错error: pathspec 'origin/XXX' did not match any file(s) known to git.
- 服务器80端口映射到8080端口
- 服务化架构下的数据一致性如何保证