json parsing encountered English double quotation marks error solution
- 2021-01-18 06:29:56
- OfStack
Analytical json, sometimes encounter with inside double quotes in English and lead to parse error, can be json escape, 1:
public static String htmlEscape(String input) {
if(isEmpty(input)){
return input;
}
input = input.replaceAll("&", "&");
input = input.replaceAll("<", "<");
input = input.replaceAll(">", ">");
input = input.replaceAll(" ", " ");
input = input.replaceAll("'", "'"); //IE Single quote entity names are not currently supported , Entity numbers with single quotes are supported , So the single quotation mark is escaped to the entity number , Other characters are escaped to the entity name
input = input.replaceAll("\"", """); // Double quotes also need to be escaped, so plus 1 Escape it with a slash
input = input.replaceAll("\n", "<br/>"); // Can't take \n The filter is put in front, because it's also on < and > Filtering, this will cause <br/> The failure
return input;
}