java kindeditor图片上传 json返回值的问题,要让kindeditor收到成功...
发布网友
发布时间:2022-04-27 11:07
我来回答
共2个回答
懂视网
时间:2022-04-25 03:29
解决办法
1.设置JSON-LIB让其过滤掉引起循环的字段。
Java代码
代码如下:
JsonConfig config = new JsonConfig();
config.setIgnoreDefaultExcludes(false);
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); //date processor register
config.setExcludes(new String[]{//只要设置这个数组,指定过滤哪些字段。
"consignee",
"contract",
"coalInfo",
"coalType",
"startStation",
"balanceMan",
"endStation"
});
String tempStr = "{"TotalRecords":"+ total.toString() +","Datas":"+JSONSerializer.toJSON(list,config).toString()+"}";
out.print(tempStr);
JsonConfig config = new JsonConfig();
config.setIgnoreDefaultExcludes(false);
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); //date processor register
config.setExcludes(new String[]{//只要设置这个数组,指定过滤哪些字段。 "consignee", "contract", "coalInfo", "coalType", "startStation", "balanceMan", "endStation" }); String tempStr = "{"TotalRecords":"+ total.toString() +","Datas":"+JSONSerializer.toJSON(list,config).toString()+"}"; out.print(tempStr);
2.设置JSON-LIB的setCycleDetectionStrategy属性让其自己处理循环,省事但是数据过于复杂的话会引起数据溢出或者效率低下。
Java代码
[code]
JsonConfig config = new JsonConfig();
config.setIgnoreDefaultExcludes(false);
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); //date processor register
String tempStr = "{"TotalRecords":"+ total.toString() +","Datas":"+JSONSerializer.toJSON(list,config).toString()+"}";
out.print(tempStr);
热心网友
时间:2022-04-25 00:37
对象转换成json对象时出现死循环,你可在把map转换时加一个配置,如下
JsonConfig jc=new JsonConfig();
jc.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
//如果用到hibeinate的话可以加以下这句,如果map里面有不想输出的属性,把属性名也加到下面,可提高效率,以下这句可选,意思是过滤掉不需要转换成json对象的属性
jc.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
JSONObject json = JSONObject.fromObject(map,jc);