I'm starting to learn how to use the Gson library in my code and need to create a list of objects from a Json file.
Json: [{"id":1,"cat":"teste","icone":"icone"},{"id":2,"cat":"teste2","icone":"icone2"}]
of this file two Objects (CategoryItem) are generated and added to the list using this code:
public static List<CategoriaItem> jsonCategoria(String json) {
List<CategoriaItem> list = new ArrayList<>();
try {
JSONArray jsonBase = new JSONArray(json);
for (int i = 0; i < jsonBase.length(); i++) {
JSONObject object = jsonBase.getJSONObject(i);
CategoriaItem categoria = new CategoriaItem(object);
list.add(categoria);
}
What settings should I make to create this same list using the Gson library?