horse Posted May 7, 2011 Share Posted May 7, 2011 Bonjour, J'essai sur android de parser un objet JSON que je récupére au format suivant: {"url":"[monURL1, monURL2, monURL3]"} en JSONArray afin de les stocker dans une ArrayList<URL>. if (entity != null) { // Lire la réponse JSON InputStream instream = entity.getContent(); JSONObject jo = new JSONObject(convertStreamToString(instream)); JSONArray jArr = new JSONArray(jo.getJSONArray("url").toString()); //JSONObject jSubObj = new JSONObject(jArr.getJSONObject(0).toString()); for(int i = 0;i<jArr.length();i++){ list.add(new URL(jArr.getJSONObject(i).toString())); } instream.close(); } Mais j'ai l'exception suivant: Value[monURL1,monURL2,monURL3] Java.lang.String cannot be converted to JSONArray Merci d'avance de votre aide ! Quote Link to comment Share on other sites More sharing options...
horse Posted May 8, 2011 Author Share Posted May 8, 2011 Personne n'a une idée ?? Quote Link to comment Share on other sites More sharing options...
moritan Posted May 9, 2011 Share Posted May 9, 2011 Pourquoi tu repasse par un toString() après ton .getJSONArray("url") tu as déjà ton jsonArray Quote Link to comment Share on other sites More sharing options...
Profete162 Posted July 2, 2011 Share Posted July 2, 2011 Je me permets de relancer le sujet car j'au un soucis semblable: Mon JSOn est de type: [{json object},{json object},{json object}] et j'aimerais le parser. Malheureusement, la méthode habituelle jo.getJSONArray("url") possède bien un argument, mais ici, en l'occurence, je n'en ai pas... Je suis vachement bloqué sur ce coup là.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.