如何使用Java读取此JSON?

时间:2018-11-11 17:03:35

标签: java json

我有这个JSON代码,但我不知道如何阅读poster_path。我知道有很多教程,但是没有一个对我有用,如果有人帮助我,那真的很棒。

{  
   "movie_results":[  
      {  
         "adult":false,
         "backdrop_path":"/j9XKiZrVeViAixVRzCta7h1VU9W.jpg",
         "genre_ids":[  
            80,
            18
         ],
         "id":278,
         "original_language":"en",
         "original_title":"The Shawshank Redemption",
         "overview":"Framed in the 1940s for the double murder of his wife and her lover, upstanding banker Andy Dufresne begins a new life at the Shawshank prison, where he puts his accounting skills to work for an amoral warden. During his long stretch in prison, Dufresne comes to be admired by the other inmates -- including an older prisoner named Red -- for his integrity and unquenchable sense of hope.",
         "poster_path":"/9O7gLzmreU0nGkIB6K3BsJbzvNv.jpg",
         "release_date":"1994-09-23",
         "title":"The Shawshank Redemption",
         "video":false,
         "vote_average":8.6,
         "vote_count":11374,
         "popularity":30.881
      }
   ],
   "person_results":[  

   ],
   "tv_results":[  

   ],
   "tv_episode_results":[  

   ],
   "tv_season_results":[  

   ]
}

1 个答案:

答案 0 :(得分:1)

使用JSONObject:

JSONOBject json = new JSONObject(string);
String posterPath = json.getJSONArray("movie_results")
                    .getJSONObject(index)
                    .getString("poster_path");