- Writer wr = response.getWriter();
- if(exceptionTrace.indexOf("'")!=-1){
- //将单引号转义一下,因为JSON串中的字符串类型可以单引号引起来的
- exceptionTrace = exceptionTrace.replaceAll("'", "\\'");
- }
- if(exceptionTrace.indexOf("\"")!=-1){
- //将双引号转义一下,因为JSON串中的字符串类型可以单引号引起来的
- exceptionTrace = exceptionTrace.replaceAll("\"", "\\\"");
- }
- if(exceptionTrace.indexOf("\r\n")!=-1){
- //将回车换行转换一下,因为JSON串中字符串不能出现显式的回车换行
- exceptionTrace = exceptionTrace.replaceAll("\r\n", "\\u000d\\u000a");
- }
- if(exceptionTrace.indexOf("\n")!=-1){
- //将换行转换一下,因为JSON串中字符串不能出现显式的换行
- exceptionTrace = exceptionTrace.replaceAll("\n", "\\u000a");
- }
- wr.write("{success:false,exception:true,msg:'" +exceptionTrace + "'}");
json转义
最新推荐文章于 2023-10-12 23:17:37 发布