Comment analyser Objet JSON Android Studio
L'Objet 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"}
Je suis en train d'analyser cet objet dans android studio toutefois im obtenir une erreur:
of type org.json.JSONObject cannot be converted to JSONArray
C'est le code que j'utilise
JSONArray mJsonArray = new JSONArray(jsonResult);
JSONObject movieObject = mJsonArray.getJSONObject(0);
String title = movieObject.getString("Title");
- Très clairement, d'après le journal :
JSONObject cannot be converted to JSONArray
signifie le besoin de changerJSONArray mJsonArray = new JSONArray(jsonResult);
àJSONObject mJsonArray = new JSONObject(jsonResult);
- et pour obtenir les valeurs à l'aide des touches de faire comme :
String title = mJsonArray.getString("Title");
et supprimerJSONObject movieObject = mJsonArray.getJSONObject(0);
ligne
Vous devez vous connecter pour publier un commentaire.
Votre json contient un objet, pas un tableau. Remplacer
par