There is a circle错误,json转换
来源:互联网 发布:控制上网的软件 编辑:程序博客网 时间:2024/06/04 18:54
在做ssh项目中,我们经常会用到ajax,服务端我们经常会返回一个json的对象,但是经常会出现这个There is a circle的错误。
错误的原因是因为hibernate中的外键关联另一个对象而另一个对象也同时关联了这个对象,造成的死循环。解决方法:
HttpServletResponse response = ServletActionContext.getResponse();response.setCharacterEncoding("utf-8");if("ajax".equals(mark)){JsonConfig config = new JsonConfig();//解决there is a cycle 问题config.setExcludes(new String[]{"empUsername","empPwd","empRemark","empAddress","empPhone","empPicturepath","empSex","manualsigns","documents","department","role","position","operationlogs","notes","messagesForSendEmp","schedules","messagesForReceiveEmp",""});JSONArray jarry = JSONArray.fromObject(employees,config);response.getWriter().write(jarry.toString());System.out.println(jarry);return null;}else{for (Employee item : employees) {employeesMap.put(item.getEmpId(),item.getEmpName());}}return "search_success";
例如,这个例子中,我只想返回一个id和一个name,但是这个对象里面拥有很多其他无关的属性包括外键对象,这个时候我们可以利用config.setExcludes();这个方法,过滤掉那些不需要的属性,然后得到的json对象就只有我们需要的这两个属性了。
- There is a circle错误,json转换
- json转换数据时候,报there is a cycle in the hierarchy!
- Json转换成字符串,There is a cycle in the hierarchy解决办法
- 使用JSONObject转换json数据报错:There is a cycle in the hierarchy!的解决办法
- JSON 转换异常 死循环 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!错误解决方案
- 使用JSON-lib时报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!错误解决方案
- 使用Json-lib转换json字符串出现There is a cycle in the hierarchy!时的解决方案
- net.sf.json.JSONException: There is a cycle in the
- json-lib There is a cycle in the hierarchy!
- JSON There is a cycle in the hierarchy异常
- net.sf.json.JSONException: There is a cycle in the
- 深入理解Linux内存映射机制
- 马拦过河卒
- irWave的Makefile
- rild进程
- ECharts使用心得
- There is a circle错误,json转换
- 使用Google Map API v2
- 黑马程序员_字符串处理
- 自学HTML之题外话
- 灰度图像的腐蚀膨胀
- 关于父类子类转换的小记录
- 津津的储蓄计划
- 中文与Unicode表示转换--java实现
- unicode utf-8 字符编解码