为什么nutzwk的上传,返回的json字符串是这样的,导致ajax回调无法解析啊
uploadcontroller的代码是:
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
@POST
@At
@Ok("json")
@RequiresAuthentication
//AdaptorErrorContext必须是最后一个参数
public Object file(@Param("Filedata") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
try {
if (err != null && err.getAdaptorErr() != null) {
return NutMap.NEW().addv("code", 1).addv("msg", "文件不合法");
} else if (tf == null) {
return Result.error("空文件");
} else {
String p = Globals.AppRoot;
String f = Globals.AppUploadPath + "/image/" + DateUtil.format(new Date(), "yyyyMMdd") + "/" + R.UU32() + tf.getSubmittedFileName().substring(tf.getSubmittedFileName().indexOf("."));
File uploadFile = new File(p + f);
Files.write(uploadFile, tf.getInputStream());
return Result.success("上传成功", Globals.AppBase+f);
}
} catch (Exception e) {
return Result.error("系统错误");
} catch (Throwable e) {
return Result.error("图片格式错误");
}
}
返回的字符串是:
<pre style="word-wrap: break-word; white-space: pre-wrap;">{"code":0,"msg":"上传成功","data":"/upload/image/20180103/o6nju9g2dog3qrpq110dv9pc9p.xls"}</pre>