我正在尝试使用 StringEscapeUtils.unescapeHtml4()替换 HTML 5 的符号,但我仍然有很多尚未替换的符号,例如“ ”、“&”。你会推荐使用什么?
问问题
1194 次
1 回答
2
 
并且&
不是实体。
并且&
是实体。如果您的字符串确实缺少;
它们,这就是它们没有被解码的原因。
我刚刚检查过(只是为了彻底!),并StringEscapeUtils.unescapeHtml4
正确解码
和&
.
正确的解决方法是修复任何给你的字符串,其中包含不完整的实体。
您可以解决它,也可以在使用后转入 
和使用:&
\u00A0
&
String#replace
StringEscapeUtils.unescapeHtml4
// Ugly, technically-incorrect workaround (but we do these things sometimes)
String result =
StringEscapeUtils.unescapeHtml4(sourceString)
.replace(" ", "\u00A0")
.replace("&", "&");
...但这是不正确的,因为那些不是实体。最好纠正字符串。
于 2016-01-21T15:22:42.227 回答