0

I want to convert a json object to an array of object in android, I use that to convert to JSON ` JSONArray jsonArr = new JSONArray();

for (Modificateurs mod : this.getModificateurs()) {
    JSONObject pnObj = new JSONObject();
        pnObj.put(Artifact.JSON_MODIFICATEUR, mod.getModificateur());
        pnObj.put(Artifact.JSON_DATEMODIFICATION, mod.getDateModification());
        jsonArr.put(pnObj);
}

Now I want to do the inverse, please help

dinotom
  • 4,990
  • 16
  • 71
  • 139
yassine
  • 71
  • 13
  • 1
    Possible duplicate of [Convert object to JSON in Android](http://stackoverflow.com/questions/5571092/convert-object-to-json-in-android) – Ed Holloway-George May 18 '16 at 08:39
  • your question is not clear – ρяσѕρєя K May 18 '16 at 08:41
  • i create a json object with arrays, now i want to do the inverse. For Example, when we have a simple string we use : this.idAr = object.getString(".."); but i don't now haw to convert when i have a list of object – yassine May 18 '16 at 08:44
  • i would rather suggest you better appraoch, use google GSON librarym most apps uses it – Sush May 18 '16 at 09:16

1 Answers1

2

Try this:

for (int i = 0; i < jsonArr.length(); i++) {
    JSONObject obj = jsonArr.getJSONObject(i);
    String modificateur = obj.optString(Artifact.JSON_MODIFICATEUR);
    String date = obj.optString(Artifcat.JSON_DATEMODIFICATION);
    Modificateurs mod = new Modificateurs(modificateur, date);
    mods.add(mod);
}
Ruben2112
  • 423
  • 4
  • 18