当前位置: 代码迷 >> JavaScript >> JsonArray: There is a cycle in the hierarchy! 有关问题解决
  详细解决方案

JsonArray: There is a cycle in the hierarchy! 有关问题解决

热度:517   发布时间:2013-03-06 16:20:31.0
JsonArray: There is a cycle in the hierarchy! 问题解决

问题:
List<Resource> res = resourceService.findAll();

JSONArray datalist = JSONArray.fromObject(res);//这里报错there is a cycle in the hierarchy

用网上提供的方法不好使下面是Resource属性???????

private Integer id; private String title;

private String description;

private Set<Role> roles = new HashSet<Role>();Resource和Role有多对多的关系Role的属性???????

private Integer id; private String roleName;

private Set<Resource> res = new HashSet<Resource>();
解决:
List<Resource> roomList=roomService.findByHotelsid(hotelsid);
??????? JsonConfig jsonConfig = new JsonConfig();
??????? jsonConfig.setJsonPropertyFilter(new net.sf.json.util.PropertyFilter(){
??????????? @Override
??????????? public boolean apply(Object source, String name, Object value) {
??????????????? if(name.equals("Roles")){
??????????????????? return true;
??????????????? }else{
??????????????? return false;
??????????????? }
??????????? }});
???????
??????? JSONArray json=JSONArray.fromObject(roomList,jsonConfig);

?

  相关解决方案