Java, get specific item from json object

664 views Asked by At

I am using TheMovieDatabase API to get data about movies. I get results with more than 200 movies. The data has this format:

{
    "results": [
        {
            "vote_count": 578,
            "id": 396422,
            "video": false,
            "vote_average": 6.4,
            "title": "Annabelle: Creation",
            "popularity": 201.166377,
            "poster_path": "/tb86j8jVCVsdZnzf8I6cIi65IeM.jpg",
            "original_language": "en",
            "original_title": "Annabelle: Creation",
            "genre_ids": [
                53,
                27
            ],
            "backdrop_path": "/o8u0NyEigCEaZHBdCYTRfXR8U4i.jpg",
            "adult": false,
            "overview": "Several years after the tragic death of their little girl, a dollmaker and his wife welcome a nun and several girls from a shuttered orphanage into their home, soon becoming the target of the dollmaker's possessed creation, Annabelle.",
            "release_date": "2017-08-03"
        },
        {
            "vote_count": 1489,
            "id": 324852,
            "video": false,
            "vote_average": 6.2,
            "title": "Despicable Me 3",
            "popularity": 111.345337,
            "poster_path": "/5qcUGqWoWhEsoQwNUrtf3y3fcWn.jpg",
            "original_language": "en",
            "original_title": "Despicable Me 3",
            "genre_ids": [
                878,
                12,
                16,
                35,
                10751
            ],
            "backdrop_path": "/puV2PFq42VQPItaygizgag8jrXa.jpg",
            "adult": false,
            "overview": "Gru and his wife Lucy must stop former '80s child star Balthazar Bratt from achieving world domination.",
            "release_date": "2017-06-15"
        },
        {
            "vote_count": 267,
            "id": 390043,
            "video": false,
            "vote_average": 6.4,
            "title": "The Hitman's Bodyguard",
            "popularity": 109.549201,
            "poster_path": "/5CGjlz2vyBhW5xHW4eNOZIdgzYq.jpg",
            "original_language": "en",
            "original_title": "The Hitman's Bodyguard",
            "genre_ids": [
                28,
                35
            ],
            "backdrop_path": "/dkA8j5DwUdUT3h658Mt1QgQHTR6.jpg",
            "adult": false,
            "overview": "The world's top bodyguard gets a new client, a hit man who must testify at the International Court of Justice. They must put their differences aside and work together to make it to the trial on time.",
            "release_date": "2017-08-16"
        }
    ]
}

How can I get a specific element? For example from all the movies I want to get 'title','release_date' and the 'poster_path' to put in 2-d table

1

There are 1 answers

0
utsav anand On

1.) Paste your JSON into [JSON to Object][1] .It will creates Object from your Json.

2.) Download the generated class and put it into your project.

3.) Crete getters and setters for the properties, then you will be able to get the properties. Ex. object.getTitle() will get the value of title.