horse 0 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 Share this post Link to post Share on other sites
horse 0 Posted May 8, 2011 Personne n'a une idée ?? Quote Share this post Link to post Share on other sites
moritan 10 Posted May 9, 2011 Pourquoi tu repasse par un toString() après ton .getJSONArray("url") tu as déjà ton jsonArray Quote Share this post Link to post Share on other sites
Profete162 59 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 Share this post Link to post Share on other sites