Dev Loppeur Dev Loppeur - 5 months ago 12
JSON Question

extract from a multiple json

I have a json like this:

[{"id":"****","value":"*****","date":"****"},
{"id":"****","value":"*****","date":"****"},
{"id":"****","value":"*****","date":"****"},
{"id":"****","value":"*****","date":"****"}]


every "sub-json" I want to convert it to Model object.(an object that contains as attributes id value and date).
How can I do it?
Thank you.

Answer

You got an array of objects.

JSONArray jsonarray = new JSONArray(jsonStr);
for (int i = 0; i < jsonarray.length(); i++) {
   JSONObject jsonobject = jsonarray.getJSONObject(i);
   String id = jsonobject.getString("id");
   String value = jsonobject.getString("value");
}
Comments