Parsing json
Kilkenny95
Messages postés
178
Statut
Membre
-
KX Messages postés 19031 Statut Modérateur -
KX Messages postés 19031 Statut Modérateur -
Bonjour,
J'aimerai parser mon JSON, j'ai le code suivant :
ma réponse est du type :
{
"STATUS": "OK",
"todo-items": [{
"id": 179,
"canComplete": true
}
Quand je run mon code j'ai l'erreur suivante : org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]
Comment la régler ?
Merci
J'aimerai parser mon JSON, j'ai le code suivant :
public class Parsing {
public String tabName[] = new String[1000];
ArrayList<String> listName = new ArrayList<String>();
public Parsing(StringBuffer responseContent) throws JSONException{
String reponseBrute = new String(responseContent.toString());
System.out.println("réponse brute = " + responseContent);
JSONArray jsonarray = new JSONArray(reponseBrute);
for (int i = 0; i < jsonarray.length() + 1; i++) {
org.json.JSONObject jsonobject = jsonarray.getJSONObject(i);
String name = jsonobject.getString("name");
tabName[i]=name;
listName.add(name);
}
}
}
ma réponse est du type :
{
"STATUS": "OK",
"todo-items": [{
"id": 179,
"canComplete": true
}
Quand je run mon code j'ai l'erreur suivante : org.json.JSONException: A JSONArray text must start with '[' at 1 [character 2 line 1]
Comment la régler ?
Merci
A voir également:
- A jsonarray text must start with '[' at 1 [character 2 line 1]
- Importer marque page firefox json ✓ - Forum Mozilla Firefox
- Convertir bookmarks*.json en bookmarks.html ✓ - Forum Windows
- Ouvrir fichier json android - Forum Windows
- Lire et convertir un fichier JSON ✓ - Forum Javascript
- Lecture fichier JSON Java pour Android studio ✓ - Forum Android
2 réponses
Bonjour,
Toi tu as fait l'inverse...
- Pour les contenus JSON en
{ ... }il faut utiliser JSONObject - Pour les contenus JSON en
[ ... ]
il faut utiliser JSONArray
Toi tu as fait l'inverse...
J'ai inversé mais j'ai des erreurs partout, pourrais tu me montrer ce que cela donne ?
Merci
Merci
Je vais te renvoyer à une de tes (nombreuses) discussions sur le même sujet.
Ici [Dal] te donnait un exemple d'utilisation de JSONObject :
https://forums.commentcamarche.net/forum/affich-36262333-recuperer-la-reponse-d-une-api-en-json#3
Ici [Dal] te donnait un exemple d'utilisation de JSONObject :
https://forums.commentcamarche.net/forum/affich-36262333-recuperer-la-reponse-d-une-api-en-json#3