Java,从json对象中获取特定项目

问题描述:

我正在使用TheMovieDatabase API来获取有关电影的数据。我收到200多部电影的结果。该数据具有以下格式:Java,从json对象中获取特定项目

{ 
    "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" 
     } 
    ] 
} 

如何获得特定元素?例如,从所有想要获得'标题','release_date'和'poster_path'的电影中放入二维表

+0

阅读类型为“Movie”的列表,然后遍历数组并获取所需信息 – Stultuske

+1

[在Java中查询JSONObject]的可能重复(https://stackoverflow.com/问题/ 15429775/query-a-jsonobject-in-java)和/或[如何在java中查询json对象](https://stackoverflow.com/questions/42485537/how-to-query-a-json-对象中的Java) – Fortega

1.)将JSON粘贴到[JSON to Object] [1] 。它会从你的Json创建对象。

2.)下载生成的类并将其放入您的项目中。

3.)克利特属性的getter和setters,那么你将能够获得属性。防爆。 object.getTitle()将获得标题的值。