java kindeditor图片上传 json返回值的问题,要让kindeditor收到成功的信息
if(!savefile.getParentFile().exists()){savefile.getParentFile().mkdirs();try{FileUtil...
if (!savefile.getParentFile().exists()) {
savefile.getParentFile().mkdirs();
try {
FileUtils.copyFile(imgFile, savefile);
map.put("error", 0);
map.put("url", savefile);
JSONObject json = JSONObject.fromObject(map);
response.getOutputStream().print(json.toString());
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
FileUtils.copyFile(imgFile, savefile);
map.put("url", savefile);
map.put("error", 0);
JSONObject json = JSONObject.fromObject(map);
System.out.println(json);
response.getOutputStream().print(json.toString());
} catch (IOException e) {
} else {
map.put("error", 1);
map.put("message", "上传失败");
JSONObject json = JSONObject.fromObject(map);
try {
response.getOutputStream().print(json.toString());
} catch {
DeBug运行到JSONObject json = JSONObject.fromObject(map);就会进入DefaultActionInvocation.class,
kindeditor报的错误信息
type Exception report
message There is a cycle in the hierarchy!
description The server encountered an internal error that prevented it from fulfilling this request.
exception
net.sf.json.JSONException: There is a cycle in the hierarchy! 展开
savefile.getParentFile().mkdirs();
try {
FileUtils.copyFile(imgFile, savefile);
map.put("error", 0);
map.put("url", savefile);
JSONObject json = JSONObject.fromObject(map);
response.getOutputStream().print(json.toString());
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
FileUtils.copyFile(imgFile, savefile);
map.put("url", savefile);
map.put("error", 0);
JSONObject json = JSONObject.fromObject(map);
System.out.println(json);
response.getOutputStream().print(json.toString());
} catch (IOException e) {
} else {
map.put("error", 1);
map.put("message", "上传失败");
JSONObject json = JSONObject.fromObject(map);
try {
response.getOutputStream().print(json.toString());
} catch {
DeBug运行到JSONObject json = JSONObject.fromObject(map);就会进入DefaultActionInvocation.class,
kindeditor报的错误信息
type Exception report
message There is a cycle in the hierarchy!
description The server encountered an internal error that prevented it from fulfilling this request.
exception
net.sf.json.JSONException: There is a cycle in the hierarchy! 展开
1个回答
展开全部
对象转换成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);
JsonConfig jc=new JsonConfig();
jc.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
//如果用到hibeinate的话可以加以下这句,如果map里面有不想输出的属性,把属性名也加到下面,可提高效率,以下这句可选,意思是过滤掉不需要转换成json对象的属性
jc.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
JSONObject json = JSONObject.fromObject(map,jc);
更多追问追答
追问
JsonConfig jc=new JsonConfig();
jc.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
然后呢,json我也是初学,很多方法都不懂..求完整点的,后面map在怎么放,还有map为什么会死循环,这个方法我在另一个地方也用过,没出现问题啊
追答
然后加JSONObject json = JSONObject.fromObject(map,jc);这句啊,单纯用SONObject json = JSONObject.fromObject(map);是直接把map对象的所有属性都转换到json对象中,加个JSONConfig是为了能可选可控的把map对象转换成json对象,
确认下,你的map是什么对象?是不是通过hibernate查询出来的实体类?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询