gpt4 book ai didi

android - 从android json响应中的字符串解析html

转载 作者:行者123 更新时间:2023-11-30 03:02:58 25 4
gpt4 key购买 nike

下面的字符串是我从 json 响应的字段之一中检索到的 >如何在下面的字符串中获取 src 的值。非常感谢任何帮助。提前致谢。

Getting better doesn’t stop because it’s getting colder. The best athletes don’t just overcome the elements, they embrace them with Nike Hyperwarm. Gear up for winter: <a href="/l.php?u=http%3A%2F%2Fwww.nike.com%2Fhyperwarm&amp;h=4AQEBIq17&amp;s=1" rel="nofollow nofollow" target="_blank" onmouseover="LinkshimAsyncLink.swap(this, &quot;http:\/\/www.nike.com\/hyperwarm&quot;);" onclick="LinkshimAsyncLink.swap(this, &quot;\/l.php?u=http\u00253A\u00252F\u00252Fwww.nike.com\u00252Fhyperwarm&amp;h=4AQEBIq17&amp;s=1&quot;);">http://www.nike.com/hyperwarm</a><br/><br/><a href="http://www.facebook.com/photo.php?v=10151882076318445" id="" title="" target="" onclick="" style=""><img class="img" src="http://vthumb.ak.fbcdn.net/hvthumb-ak-ash3/t15/1095964_10151882078663445_10151882076318445_40450_2013_b.jpg" alt="" style="height:90px;" /></a><br/><a href="http://www.facebook.com/photo.php?v=10151882076318445" id="" style="">Winning in a Winter Wonderland</a>

最佳答案

尝试使用 jsoup html 解析 api 具有用于 html 解析的专用功能,并且还将提供可扩展的解决方案。

对于您的情况(我转义引号和附加的 \ 以使其成为有效的 Java 字符串):

String str = "Getting better doesn’t stop because it’s getting colder. The best athletes don’t just overcome the elements, they embrace them with Nike Hyperwarm. Gear up for winter: <a href=\"/l.php?u=http%3A%2F%2Fwww.nike.com%2Fhyperwarm&amp;h=4AQEBIq17&amp;s=1\" rel=\"nofollow nofollow\" target=\"_blank\" onmouseover=\"LinkshimAsyncLink.swap(this, &quot;http:\\/\\/www.nike.com\\/hyperwarm&quot;);\" onclick=\"LinkshimAsyncLink.swap(this, &quot;\\/l.php?u=http\u00253A\u00252F\u00252Fwww.nike.com\u00252Fhyperwarm&amp;h=4AQEBIq17&amp;s=1&quot;);\">http://www.nike.com/hyperwarm</a><br/><br/><a href=\"http://www.facebook.com/photo.php?v=10151882076318445\" id=\"\" title=\"\" target=\"\" onclick=\"\" style=\"\"><img class=\"img\" src=\"http://vthumb.ak.fbcdn.net/hvthumb-ak-ash3/t15/1095964_10151882078663445_10151882076318445_40450_2013_b.jpg\" alt=\"\" style=\"height:90px;\" /></a><br/><a href=\"http://www.facebook.com/photo.php?v=10151882076318445\" id=\"\" style=\"\">Winning in a Winter Wonderland</a>\"";
Document doc = Jsoup.parse(str);
Element element = doc.select("img").first();
System.out.println(element.attr("src"));
Element element2 = doc.select("a").first(); // Get the anchor tag element
System.out.println(element2.attr("onclick")); // onclick as attribute for anchor tag

输出;

http://vthumb.ak.fbcdn.net/hvthumb-ak-ash3/t15/1095964_10151882078663445_10151882076318445_40450_2013_b.jpg

关于android - 从android json响应中的字符串解析html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22280681/

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