在 Android 上使用 Java 我正在努力转换几个 html 特殊字符。
到目前为止我已经尝试过:
String myString = "%A32.00%20per%20month%B3";
Html.fromHtml(myString).toString(); => %A32.00%20per%20month%B3
URLDecoder.decode(myString) => �2.00 per month�
URLDecoder.decode(myString, "UTF-8") => �2.00 per month�
URLDecoder.decode(myString, "ASCII") => �2.00 per month�
org.apache.commons.lang.StringEscapeUtils.unescapeHtml4(myString) => %A32.00%20per%20month%B3
正确的输出应该是 => £2.00 per month³
最佳答案
您的字符串以 ISO-8859-1
编码,因此 ASCII 和 UTF-8 将不起作用。
String myString = "%A32.00%20per%20month%B3";
URLDecoder.decode(myString, "ISO-8859-1");
// output: £2.00 per month³
关于java - HTML特殊字符解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8578904/