Jump to content

JSON Parsing en JSONArray sur android


Recommended Posts

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 !

Link to comment
Share on other sites

  • 1 month later...

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à..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...