提问人:Kotlin Learner 提问时间:1/18/2022 更新时间:1/18/2022 访问量:1401
在 kotlin 中解析 json 响应中的 html 标签
Parse html tag from json response in kotlin
问:
嘿,我正在 kotlin 中使用带有 html 标签的 json 响应。我不明白如何解析html标签作为响应。我尝试使用 retrofit 和 moshi。我的回答是这样的
响应
{
"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 = 'bar';</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中我们可以做到吗?
答:
0赞
Farhan Muhammad
1/18/2022
#1
您可以将这些 html 代码呈现到文本视图中,尝试使用此库来执行此操作。https://github.com/SysdataSpA/SDHtmlTextView
编辑: 您还可以使用 WebView 来呈现 html。
评论
0赞
Kotlin Learner
1/18/2022
我们可以没有图书馆吗?
0赞
Farhan Muhammad
1/18/2022
是的,您可以,请按照以下示例操作:stackoverflow.com/a/2116191/11209575
0赞
Kotlin Learner
1/19/2022
此库不工作
0赞
Farhan Muhammad
1/22/2022
抱歉久等了,你解决了吗?如果您还没有,请提供导致它不起作用的信息。
0赞
Kotlin Learner
1/23/2022
当我尝试添加依赖项时,它给出错误
评论