how to get all Arrays from JSONObject?

anehme :

I am trying to get data from JsonObject like this :

{
  "status": "ok",
  "data_EN": [
    {
      "id": 1,
      "url" :"http://exemple.com"
    }
  ],
  "data_FR": [...],
  "data_ES": [...]
}

I created a method to get this response , i can get only one array using JSONArray but i cannot found a method to get all data from this arrays

 ItemGroup itemGroup = new ItemGroup();
 JSONObject jsonObject = new JSONObject(response);

 JSONArray jsonArray = jsonObject.getJSONArray("data_EN");
 itemGroup.setTitle("data_EN");
 List<Data> items = new Gson().fromJson(jsonArray.toString(), new TypeToken<List<Data>>() {
                            }.getType());

 itemGroup.setData(items);
 itemGroups.add(itemGroup);

Thanks for your help.

Jamaldin Sabirjanov :

Try creating models:

ItemResponse.class

public class ItemResponse {
    private String status;
    private List<Item> data_EN;
    private List<Item> data_FR;
    private List<Item> data_ES;
}

Item.class

public class Item {
    private long id;
    private String url;
}

So you can then get it by:

ItemResponse itemResponse = new Gson().fromJson(jsonObject.toString(), ItemResponse.class);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=385131&siteId=1