yassine
yassine

Reputation: 71

Convert From json Android

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

Upvotes: 0

Views: 75

Answers (1)

Ruben2112
Ruben2112

Reputation: 423

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);
}

Upvotes: 2

Related Questions