Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backs


Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value


出现这个错误 是因为使用了 ObjectMapper来转换json字符串,

解决的办法是 1 避免使用这个类
             google 的 Gson gson =new Gson() 就是个替代方案,具体的效率问题不讨论
             2 使用 ObjectMapper mapper=new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);

             3 在传入值的时候,去除回车符 换行符 制表符 等


public static boolean isBlankOrNull(String str){  
        if(null==str)return true;  
           return str.length()==0;  
    }  
	
	/**
	 * //去除字符串中空格、换行、制表 
	 * @param str
	 * @param pattern
	 * @param replace
	 * @return
	 */
	public static String replaceSpecialtyStr(String str,String pattern,String replace){  
         if(isBlankOrNull(pattern))  
             pattern="\\s*|\t|\r|\n"; 
         if(isBlankOrNull(replace))  
             replace="";  
         return Pattern.compile(pattern).matcher(str).replaceAll(replace);  
     }

你可能感兴趣的:(Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backs)