There is a cycle in the hierarchy! json转换异常

li8412281 2017-08-16 01:46:19
在网上看到了很多方法 使用 jsonconfig 过滤掉属性 还是不行
public void plist() {
// TODO Auto-generated method stub
List<Province> plist=pcd.plist();
JsonConfig config=new JsonConfig();
config.setJsonPropertyFilter(new PropertyFilter() {

@Override
public boolean apply(Object arg0, String arg1, Object arg2) {
// TODO Auto-generated method stub
if(arg1.equals("cities")||arg1.equals("userinfos")){
return true;
}
return false;
}
});
JSONArray json=JSONArray.fromObject(plist,config);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
try {
response.getWriter().write(json.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
...全文
134 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
li8412281 2017-08-16
  • 打赏
  • 举报
回复
跪求大神帮忙解决!
li8412281 2017-08-16
  • 打赏
  • 举报
回复
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.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.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._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._fromCollection(JSONArray.java:1056)
li8412281 2017-08-16
  • 打赏
  • 举报
回复
<hibernate-mapping> <class name="com.lee.bbs.entity.Province" table="PROVINCE" schema="BBS"> <id name="pid" type="java.lang.Integer"> <column name="PID" precision="0" /> <generator class="assigned" /> </id> <property name="pname" type="java.lang.String"> <column name="PNAME" length="40" not-null="true" /> </property> <set name="cities" inverse="true" lazy="false"> <key> <column name="PID" precision="0" not-null="true" /> </key> <one-to-many class="com.lee.bbs.entity.City" /> </set> <set name="userInfos" inverse="true" lazy="false"> <key> <column name="PID" precision="0" not-null="true" /> </key> <one-to-many class="com.lee.bbs.entity.UserInfo" /> </set> </class> </hibernate-mapping>

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧