简体   繁体   English

Java,从json对象获取特定项

[英]Java, get specific item from json object

I am using TheMovieDatabase API to get data about movies. 我正在使用TheMovieDatabase API来获取有关电影的数据。 I get results with more than 200 movies. 我得到超过200部电影的结果。 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 例如,从所有我想要获取的“电影”,“ release_date”和“ poster_path”放入二维表中的电影

1.) Paste your JSON into [JSON to Object][1] .It will creates Object from your Json. 1.)将您的JSON粘贴到[JSON to Object] [1]中。它将从您的Json创建Object。

2.) Download the generated class and put it into your project. 2.)下载生成的类并将其放入您的项目中。

3.) Crete getters and setters for the properties, then you will be able to get the properties. 3)属性的克里特吸气剂和塞特剂,那么您将能够获得属性。 Ex. 例如 object.getTitle() will get the value of title. object.getTitle()将获取title的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM