fastJson数组添加元素时禁用循环引用
2017-03-29 17:22
686 查看
当使用fastJson时,在JSONArray中add多个json对象,若各json中存在相同元素,则会出现ref{…}表示的循环引用,想要禁止循环引用,则对加入JSONArray中的每个元素进行如下转换,再add到JSONArray即可。
String str = JSON.toJSONString(json,SerializerFeature.DisableCircularReferenceDetect);
JSONObject j = JSON.parseObject(str);
arry.add(j); /**
* 列表数据(已知应用id)
*
* @param appId
* @param request
* @param response
* @return
*/
public JSONArray tabData2(String appId ) {
DataSourceHolder.setDataSources(Global.getConfig("centerDataSource"));
Service app = serviceService.get(appId);
DataSourceHolder.reSet();
Map<String, String> map = new HashMap<String, String>();
JSONArray arry = new JSONArray();
JSONObject json = new JSONObject();
if (app != null && StringUtils.isNotBlank(app.getId())) {
List<Api> apiList = apiData(app.getId());
for (Api api : apiList) {
if (api != null && StringUtils.isNotBlank(api.getId())) {
List<Apply> applyList = applyData(api.getId());
for (Apply a : applyList) {
map = statisticData(a.getId(), api.getId());
json.put("success", map.get("success"));
json.put("failure", map.get("failure"));
json.put("applyOffice", a.getCreateBy().getCompany().getName());
json.put("applyName", a.getCreateBy().getName());
json.put("apiName", api.getName());
json.put("resTime", map.get("resTime"));
String str = JSON.toJSONString(json,SerializerFeature.DisableCircularReferenceDetect);
JSONObject j = JSON.parseObject(str);
arry.add(j);
System.out.println(arry);
}
}
}
}
return arry;
}
String str = JSON.toJSONString(json,SerializerFeature.DisableCircularReferenceDetect);
JSONObject j = JSON.parseObject(str);
arry.add(j); /**
* 列表数据(已知应用id)
*
* @param appId
* @param request
* @param response
* @return
*/
public JSONArray tabData2(String appId ) {
DataSourceHolder.setDataSources(Global.getConfig("centerDataSource"));
Service app = serviceService.get(appId);
DataSourceHolder.reSet();
Map<String, String> map = new HashMap<String, String>();
JSONArray arry = new JSONArray();
JSONObject json = new JSONObject();
if (app != null && StringUtils.isNotBlank(app.getId())) {
List<Api> apiList = apiData(app.getId());
for (Api api : apiList) {
if (api != null && StringUtils.isNotBlank(api.getId())) {
List<Apply> applyList = applyData(api.getId());
for (Apply a : applyList) {
map = statisticData(a.getId(), api.getId());
json.put("success", map.get("success"));
json.put("failure", map.get("failure"));
json.put("applyOffice", a.getCreateBy().getCompany().getName());
json.put("applyName", a.getCreateBy().getName());
json.put("apiName", api.getName());
json.put("resTime", map.get("resTime"));
String str = JSON.toJSONString(json,SerializerFeature.DisableCircularReferenceDetect);
JSONObject j = JSON.parseObject(str);
arry.add(j);
System.out.println(arry);
}
}
}
}
return arry;
}
相关文章推荐
- FastJson禁用循环引用检测
- superobject数组添加json对象,用的是引用
- 在springmvc中解决FastJson循环引用的问题
- 向json数组添加元素
- 【FastJSON】解决FastJson中“$ref 循环引用”的问题
- springmvc中解决FastJson循环引用的问题
- IOS学习 NSOperation cell存储图片思路 沙盒路径查找 数组中添加空对象 block循环引用风险
- 解决fastjson循环引用问题(死循环)
- 动态创建表格,更新、提交、循环获取表格中各种元素的数据 并转换为JSON,数组的数据格式。
- webapi修改tt模板给字段添加JsonIgnore特性解决转换json循环引用问题
- 【Java】消除fastjson对同一对象循环引用的问题
- 【FastJSON】解决FastJson中“$ref 循环引用”的问题
- 【FastJSON】解决FastJson中“$ref 循环引用”的问题
- 在springmvc中解决FastJson循环引用的问题
- 解析javascript 数组以及json元素的添加删除
- 修改一行代码,解决在C++ Builder平台上JSONCPP向数组添加元素的Bug
- 在springmvc中解决FastJson循环引用的问题
- bootstrap table处理含有子集json的数据以及fastjson禁止循环引用的问题
- HTML循环取JSON数组里面的数据,添加容错判断。
- JSON工具学习记录--FastJSON循环引用问题