我想将 jsoup 解析为 utf -8 但我不能。我尝试了我所知道的一切,并在谷歌上进行了搜索。
我的目标是什么:
String tmp_html_content ="Öç";
InputStream is = new ByteArrayInputStream(tmp_html_content.getBytes());
Document doc_tbl = Jsoup.parse(is, "UTF-8", "");
doc_tbl.outputSettings().charset().forName("UTF-8");
doc_tbl.outputSettings().escapeMode(EscapeMode.xhtml);
但是 doc_tbl
不是 UTF-8
。
请帮忙解决
最佳答案
public static void main(String []args){
System.out.println("Hello World");
String tmp_html_content ="Öçasasa";
InputStream is = new ByteArrayInputStream(tmp_html_content.getBytes());
org.jsoup.nodes.Document doc_tbl;
try {
doc_tbl = Jsoup.parse(is, "ISO-8859-9", "");
((org.jsoup.nodes.Document) doc_tbl).outputSettings().charset().forName("UTF-8");
((org.jsoup.nodes.Document) doc_tbl).outputSettings().escapeMode(EscapeMode.xhtml);
String htmlString = doc_tbl.toString();
System.out.println(htmlString);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
输出
Hello World 奥萨萨萨
关于java - 为什么 JSOUP 不能读取为 UTF-8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24218239/