问题:
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);
相关推荐
JSONArray需要的jar包
java jsonarray 踢重 去重操作
JSONArray需要的jar包,包含以下: json-lib-2.4-jdk15.jar json-lib-2.4.jar ezmorph-1.0.6.jar commons-logging-1.1.1.jar commons-lang-2.6.jar commons-collections-3.2.1.jar commons-beanutils-1.9.2....
JSONArray解析包,JSONArray.fromObject使用,可以解析map,list等
给出提前排序的数组,jsonArray中字段根据数组顺序重新排序。
JSONArray常用包.rar,非常实用的包包,请查收。
这是一个关于JSONArray实现的一个小实例,代码比较简单,目的在于理解JSONArray的实现
3.JSONArray:fastJson提供json数组对象 --------------------- 作者:superlovelei 来源:CSDN 原文:https://blog.csdn.net/superlover_/article/details/79741075 版权声明:本文为博主原创文章,转载请附上...
JSONObject、JSONArray需要的jar包,需要的可以直接联系
使用JSONArray.fromObject所需要的jar包,不使用的话会导致JSONArray.fromObject方法报错
JSONArray的使用 附带程序注释与输出
Servlet 处理 AJAX中传递的JSON格式参数,JSON中含有JSONArray!在网上搜索资源时发现没有相关内容,所以自己写了一下跟大家一起分享!如有雷同,纯属巧合!第一次传资源,有不好的地方希望大家提出建议!
JSONObject与JSONArray所需jar包 ===JSONObject与JSONArray所需jar包
JSONArray JSONObject所需JAR json-lib-2.4-jdk15.jar commons-beanutils-1.9.2.jar commons-collections-3.2.1.jar commons-lang-2.5.jar commons-logging-1.1.1.jar ezmorph-1.0.6.jar
net.sf.json.JSONArray等JSON类所需要的jar包组合。包括JSONObject等
使用jsonArray.fromObject转json必须导入五个jar, 包含:commons-lang.jar commons-beanutils.jar commons-collections.jar commons-logging.jar ezmorph.jar json-lib-2.2.2-jdk15.jar
一些常用的json包如:commons-logging-1.0.4.jar commons-lang-2.3.jar commons-collections-3.2.jar commons-beanutils-1.7.0.jar 等
关于使用JSONArray.fromObject()方法和引入net.sf.json包所需要的依赖包:commons-beanutils.jar,commons-httpclient.jar,commons-lang.jar,ezmorph.jar,morph-1.0.1.jar
包含 json-lib-2.4-jdk15.jar , ezmorph-1.0.6.jar commons-logging-1.2.jar commons-lang-2.5.jar commons-collections-3.2.jar commons-beanutils-1.8.0.jar
JSON使用