所以我正在使用这个json url: https://api.flickr.com/services/feeds/photos_public.gne?format=json
JSON数组的示例JSON对象如下所示:
{
"title": "I love my profession..",
"link": "https://www.flickr.com/photos/140275258@N03/27217061344/",
"media": {"m":"https://farm8.staticflickr.com/7437/27217061344_95ba3d0dd9_m.jpg"},
"date_taken": "2016-05-07T15:33:43-08:00",
"description":
" <p><a href=\"https://www.flickr.com/people/140275258@N03/\">N Javier Contreras<\/a> posted a photo:<\/p>
<p><a href=\"https://www.flickr.com/photos/140275258@N03/27217061344/\"
title=\"I love my profession..\">
<img src=\"https://farm8.staticflickr.com/7437/27217061344_95ba3d0dd9_m.jpg\"
width=\"240\"
height=\"120\"
alt=\"I love my profession..\" /><\/a><\/p>
<p>Yellow.<\/p>",
"published": "2016-06-22T03:43:49Z",
"author": "nobody@flickr.com (N Javier Contreras)",
"author_id": "140275258@N03",
"tags": "world chile auto china camera nyc newyorkcity family school wild sculpture naturaleza india white fish chicago ontario storm color macro history classic cars texture home me apple leaves fog stone stairs contrast digital america canon buildings hair mexico gold golden fly photo waterfall high couple warm moments cityscape fuji photos dusk 5 sunny pic bee cielo second sur photograpy monocromatico alairelibre"
}
我需要存储描述中的第三个URL(img src),alt,width和height值。
有人可以告诉我如何存储所需的值。我还需要用第一个<p>
标签写的用户名&#34; N Javier Contreras&#34;在这种情况下。我正面临问题,因为说明文字中有HTML标签。
我知道我可以使用title
对象获取标题和media
对象来获取URl,但我仍然需要从描述文本中获取宽度和高度。
PS:我是JSON和HTML的新手,这就是为什么我自己无法做到这一点。任何有用链接的帮助或建议都表示赞赏。
答案 0 :(得分:1)
您可以使用jsoup库来完成此操作。喜欢这个
String description = " <p><a href=\"https://www.flickr.com/people/140275258@N03/\">N Javier Contreras<\/a> posted a photo:<\/p>
<p><a href=\"https://www.flickr.com/photos/140275258@N03/27217061344/\"
title=\"I love my profession..\">
<img src=\"https://farm8.staticflickr.com/7437/27217061344_95ba3d0dd9_m.jpg\"
width=\"240\"
height=\"120\"
alt=\"I love my profession..\" /><\/a><\/p>
<p>Yellow.<\/p>",
Document doc = Jsoup.parse(description);
Element link = doc.select("img").first();
String linkSrc = link.attr("src");
String linkAlt = link.attr("alt");
// and so on you want