Aller au contenu

parse json


Recommended Posts

Bonjour.

je n'arrive pas à parser un doc en json.

mon doc ressemble à ça:

[{"id":"1","nom","jean"},{"id":"2","nom":"paul"}]

Mais je n'arrive pas trop a trouver comment le transformer en tableau.

par exemple en javascript c'est simple il y a juste JSON.parse

j'ai essayé mais sans trop de succès

public JSONObject parseJson() throws JSONException{
JSONObject jsonObject = new JSONObject(html);
return jsonObject;
}

a chaque fois l'erreur est levée (html est mon json en string)

Pourriez vous m'aider ??

Merci :)

Edit:

j'ai trouvé :)

JSONArray jsonRootArray = new JSONArray (“[{"id":"1","nom","jean"},{"id":"2","nom":"paul"}]”);

for (int i = 0; i < jsonRootArray.length(); i++)

{

JSONObject jsonObj = jsonRootArray.getJSONObject(i);

String strId = jsonObj.getString("id");

String strName = jsonObj.getString("nom");

}

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...