安卓如何在java中恢复html内容?
我正在将一些html代码作为文本保存到mysql数据库中。我用截取的方式将文本作为字符串检索。当我保存html时,某些不需要的值会添加到html内容中。如何删除此不需要的内容并显示html内容。我使用webview来显示此内容,并使用jsoup来解析它。
这是我使用Document doc = Jsoup.parse(instruction);
解析html内容后得到的结果
<html>
<head></head>
<body>
{"result":[{"instruction":"\n\n\u00a0 \u00a0<\/head>\n\n\u00a0 \u00a0\n\n\u00a0 \u00a0 \u00a0
<ul>
\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0
<li>The Comprehensive R Archive Network<\/li>\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0</li>
<li>
A network of global web servers storing identical, up-to-date, versions of<br \="" />code and documentation for R<\/li>\n\n\u00a0 \u00a0 \u00a0 <\/ul>\n\n\u00a0 \u00a0 \u00a0
<p><br \="" /><strong>Download and Install R:<\/strong><\/p>\n\n\u00a0 \u00a0 \u00a0 </strong></p>
<ul>
<strong>
\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0
<li>Use the CRAN mirror nearest to you to download R setup at a faster<br \="" />speed. Go to <a href="\"url\"">\u00a0http:\/\/cran.r-project.org<\/a><\/li>\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0</a></li>
<li>
<a href="\"url\"">
Select one of the three download links according to your machine.<\/li>\n\n\u00a0 \u00a0 \u00a0 <\/ul>\n\n\u00a0 \u00a0 \u00a0 <img src="\"file:\/\/\/storage\/emulated\/0\/rreadyreckoner_images\/download-r.png\"" alt="\"downloadr\"" width="\"191\"" height="\"129\"" \="" />\u00a0\n\n\u00a0 \u00a0 \u00a0
<ul>
\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0
<li>Run the R set up and follow the instructions of the installer.<\/li>\n\n\u00a0 \u00a0 \u00a0 <\/ul>\n\n\u00a0 \u00a0<\/body>\n\n<\/html>\n\n"}]} </li>
</ul>
</a>
</li>
</strong>
</ul>
</li>
</ul>
</body>
</html>
是否有一种方法可以将html内容检索为字符串,然后将其重构为纯html并在webview中显示。我是编程新手,因此任何帮助或建议都将不胜感激。多谢各位
# 1 楼答案
您可以使用
org.apache.commons.lang3.StringEscapeUtils.unescapeJava(text)
转义unicode字符,如\u00a0
;使用org.apache.commons.lang3.StringEscapeUtils.unescapeHtml4(text)
转义html编码字符,如"
StringEscapeUtils
类可以从Apache Commons中获得