如何解析JSON对象Android Studio

时间:2015-11-16 19:20:43

标签: java android json api

JSON对象

{"Title":"Batman Returns","Year":"1992","Rated":"PG-13","Released":"19 Jun 1992","Runtime":"126 min","Genre":"Action","Director":"Tim Burton","Writer":"Bob Kane (Batman characters), Daniel Waters (story), Sam Hamm (story), Daniel Waters (screenplay)","Actors":"Michael Keaton, Danny DeVito, Michelle Pfeiffer, Christopher Walken","Language":"English","Country":"USA, UK","Awards":"Nominated for 2 Oscars. Another 2 wins & 15 nominations.","Poster":"http://ia.media-imdb.com/images/M/MV5BODM2OTc0Njg2OF5BMl5BanBnXkFtZTgwMDA4NjQxMTE@._V1_SX300.jpg","Metascore":"N/A","imdbRating":"7.0","imdbVotes":"199,878","imdbID":"tt0103776","Type":"movie","Response":"True"}

我试图在android studio中解析这个对象但是我得到一个错误:

of type org.json.JSONObject cannot be converted to JSONArray

这是我使用的代码

JSONArray mJsonArray = new JSONArray(jsonResult);
JSONObject movieObject = mJsonArray.getJSONObject(0);

String title = movieObject.getString("Title");

1 个答案:

答案 0 :(得分:2)

你的json包含一个对象,而不是一个数组。取代

JSONArray mJsonArray = new JSONArray(jsonResult);

通过

JSONObject movieObject = new JSONObject(jsonResult);    
String title = movieObject.getString("Title");