我正在尝试json解码一个字符串,但我得到一个错误:
"message":"error while converting json to class","level":"ERROR","level_value":40000,"stack_trace":"com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 31)): has to be escaped using backslash to be included in string value\n at [Source: { \"key\": \"abc No.\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F\u001F 106,xyz}
我怀疑json中可能有一个ctrl-char字符(/ n)。我想知道如何在这个ctrl-char可能存在的地方添加额外的转义字符,这样我的代码在解码json时不会中断。
Json解码代码:
public static Object jsonDecode(String s, Class c) {
Object u = null;
if(s!=null) {
try {
u = objectMapper.reader(c)
.readValue(s);
} catch (Exception e) {
logger.error("error while converting json to class", e);
}
}
return u;
}