gpt4 book ai didi

java - 如何在java中恢复html内容?

转载 作者:行者123 更新时间:2023-11-30 22:14:02 24 4
gpt4 key购买 nike

我将一些 html 代码作为文本保存到 mysql 数据库中。我使用 volley 将此文本作为字符串检索。当我保存 html 时,某些不需要的值会添加到 html 内容中。如何删除这些不需要的内容并显示 html 内容。我正在使用 webview 来显示此内容并使用 jsoup 来解析它。这是我使用 Document doc = Jsoup.parse(instruction);

解析 html 内容后得到的结果
 <html>
<head></head>
<body>
{&quot;result&quot;:[{&quot;instruction&quot;:&quot;\n\n\u00a0 \u00a0&lt;\/head&gt;\n\n\u00a0 \u00a0\n\n\u00a0 \u00a0 \u00a0
<ul>
\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0
<li>The Comprehensive R Archive Network&lt;\/li&gt;\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&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\n\n\u00a0 \u00a0 \u00a0
<p><br \="" /><strong>Download and Install R:&lt;\/strong&gt;&lt;\/p&gt;\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="\&quot;url\&quot;">\u00a0http:\/\/cran.r-project.org&lt;\/a&gt;&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0</a></li>
<li>
<a href="\&quot;url\&quot;">
Select one of the three download links according to your machine.&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\n\n\u00a0 \u00a0 \u00a0 <img src="\&quot;file:\/\/\/storage\/emulated\/0\/rreadyreckoner_images\/download-r.png\&quot;" alt="\&quot;downloadr\&quot;" width="\&quot;191\&quot;" height="\&quot;129\&quot;" \="" />\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.&lt;\/li&gt;\n\n\u00a0 \u00a0 \u00a0 &lt;\/ul&gt;\n\n\u00a0 \u00a0&lt;\/body&gt;\n\n&lt;\/html&gt;\n\n&quot;}]} </li>
</ul>
</a>
</li>
</strong>
</ul>
</li>
</ul>
</body>
</html>

有没有一种方法可以将 html 内容检索为字符串,然后将其重构为纯 html 并将其显示在 webview 中。我是编程新手,因此不胜感激任何帮助或建议。谢谢。

最佳答案

您可以使用 org.apache.commons.lang3.StringEscapeUtils.unescapeJava(text) 转义 unicode 字符,例如 \u00a0org.apache.commons .lang3.StringEscapeUtils.unescapeHtml4(text) 转义 html 编码字符,如 "

StringEscapeUtils 类可以从Apache Commons获得.

关于java - 如何在java中恢复html内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39072084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com