如何在 Java 中从 HTML 转换为 UTF-8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2825985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert from HTML to UTF-8 in java
提问by Llistes Sugra
I have an ASCII String, with HTML entities, like:
我有一个带有 HTML 实体的 ASCII 字符串,例如:
à
¨
ç
I need this String to be without those entities and convert them into UTF-8 chars. Is there any easy way, in java to do that?
我需要这个字符串没有这些实体并将它们转换为 UTF-8 字符。有没有什么简单的方法,在java中做到这一点?
Where:
在哪里:
Clazz.method("aà","UTF-8")
returns "aà"
返回“aà”
or something like that?
或类似的东西?
回答by Stephen C
Take a look at org.apache.commons.lang.StringEscapeUtils.unescapeHtml(...). Apparently it understands all character entities defined in HTML 4.
看看org.apache.commons.lang.StringEscapeUtils.unescapeHtml(...)。显然它理解 HTML 4 中定义的所有字符实体。

