【问题标题】:Parse html tag from json response in kotlin从 kotlin 中的 json 响应解析 html 标签
【发布时间】:2022-01-18 20:29:51
【问题描述】:

嘿,我正在使用 kotlin 中的 html 标签处理 json 响应。我不明白如何解析 html 标签作为响应。我尝试使用retrofitmoshi。我的回复会是这样的

回应

{
  "items": [
    {
      "id": "1",
      "date": "2021-11-01",
      "title": "<html><head><style>body {
   color: black;
}
</style></head><body><h1 id="sample-markdown">Sample Markdown</h1>
<p>This is some basic, sample markdown.</p>
<h2 id="second-heading">Second Heading</h2>
<ul>
<li>Unordered lists, and:<ol>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ol>
</li>
<li>More</li>
</ul>
<blockquote>
<p>Blockquote</p>
</blockquote>
<p>And <strong>bold</strong>, <em>italics</em>, and even <em>italics and later <strong>bold</strong></em>. Even <del>strikethrough</del>. <a href="https://markdowntohtml.com">A link</a> to somewhere.</p>
<p>And code highlighting:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> foo = <span class="hljs-string">'bar'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">baz</span><span class="hljs-params">(s)</span> </span>{
   <span class="hljs-keyword">return</span> foo + <span class="hljs-string">':'</span> + s;
}
</code></pre>
<p>Or inline code like <code>var foo = &#39;bar&#39;;</code>.</p>
<p>Or an image of bears</p>
<p><img src="http://placebear.com/200/200" alt="bears"></p>
<p>The end ...</p>
</body></html>"
    }
  ]
}

我想在文本视图中显示title

在android中我们可以做到吗?

【问题讨论】:

    标签: android json kotlin retrofit2 html-parsing


    【解决方案1】:

    您可以将这些 html 代码呈现到文本视图中,尝试使用此库来执行此操作。 https://github.com/SysdataSpA/SDHtmlTextView

    编辑: 也可以使用 WebView 来渲染 html。

    【讨论】:

    • 我们可以不用图书馆吗?
    • 是的,你可以,按照这个例子:stackoverflow.com/a/2116191/11209575
    • 这个库不工作
    • 抱歉,您解决了吗?如果您还没有,请提供信息导致它不起作用。
    • 当我尝试添加依赖时它给出错误
    猜你喜欢
    • 1970-01-01
    • 2019-11-27
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多