0

So I'am using this json url: https://api.flickr.com/services/feeds/photos_public.gne?format=json

Sample JSON object of a JSON array looks like:

{
            "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": "[email protected] (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"
       }

I need to store third URL(img src), alt, width and height values from description. Can someone tell how can I store the desired values. I also need the username which is written in the first <p> tag "N Javier Contreras" in this case. I'am facing problem because there are HTML tags in the description text. I know that I can use the title object to get the title and media object to get the URl but I will still need to get width and height from the description text.

PS: I'am new to JSON and HTML so thats why I can't do it myself. Any help or recommendation of helpful links is appreciated.

1 Answer 1

1

You can do this by using jsoup library. Like this

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 
Sign up to request clarification or add additional context in comments.

3 Comments

For reference how to add jsoup visit this link stackoverflow.com/questions/8817978/…
what do I need to do in order to get the username which is written in the first <p> tag "N Javier Contreras" in this case.
It is first <a> tag. Then use Element link2 = doc.select("a").first(); String text=link2.text();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.