net.sf.json.JSONException: There is a cycle in the hierarchy
net.sf.json.JSONException: There is a cycle in the hierarchy! atnet.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97) atnet.sf.json.JSONObject._fromBean(JSONObject.java:833) atnet.sf.json.JSONObject.fromObject(JSONObject.java:168) atnet.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) atnet.sf.json.JSONObject._processValue(JSONObject.java:2808) atnet.sf.json.JSONObject.processValue(JSONObject.java:2874) atnet.sf.json.JSONObject.setInternal(JSONObject.java:2889) atnet.sf.json.JSONObject.setValue(JSONObject.java:1577) atnet.sf.json.JSONObject._fromBean(JSONObject.java:934) atnet.sf.json.JSONObject.fromObject(JSONObject.java:168) atnet.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) atnet.sf.json.JSONArray._processValue(JSONArray.java:2514) atnet.sf.json.JSONArray.processValue(JSONArray.java:2539) atnet.sf.json.JSONArray.addValue(JSONArray.java:2526) atnet.sf.json.JSONArray._fromCollection(JSONArray.java:1057) atnet.sf.json.JSONArray.fromObject(JSONArray.java:123) atnet.sf.json.AbstractJSON._processValue(AbstractJSON.java:237) atnet.sf.json.JSONObject._processValue(JSONObject.java:2808) atnet.sf.json.JSONObject.processValue(JSONObject.java:2874) atnet.sf.json.JSONObject.setInternal(JSONObject.java:2889) atnet.sf.json.JSONObject.setValue(JSONObject.java:1577) atnet.sf.json.JSONObject._fromBean(JSONObject.java:934) atnet.sf.json.JSONObject.fromObject(JSONObject.java:168) atnet.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) atnet.sf.json.JSONArray._processValue(JSONArray.java:2514) atnet.sf.json.JSONArray.processValue(JSONArray.java:2539) atnet.sf.json.JSONArray.addValue(JSONArray.java:2526) atnet.sf.json.JSONArray._fromCollection(JSONArray.java:1057) atnet.sf.json.JSONArray.fromObject(JSONArray.java:123) atnet.sf.json.JSONArray.fromObject(JSONArray.java:105) atcn.csdn.city.servlet.CityJsonServlet.doGet(CityJsonServlet.java:34) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:617) atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717) atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291) atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) atjava.lang.Thread.run(Thread.java:619) 解决办法: ProvinceService pService = new ProvinceServiceImpl(); List<Province> province = pService.getObjects(); JsonConfig config = new JsonConfig(); config.setJsonPropertyFilter(new PropertyFilter() {
public boolean apply(Object source,String name,Object value) { if(name.equals("city")){ return true; }else{
return false; } } });
PrintWriter out = response.getWriter(); out.println(JSONArray.fromObject(province,config).toString()); out.flush(); out.close(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |