jsonarray to list java code example
Example 1: jsonarray to list java
JSONArray data = new JSONArray();
List<JSONObject> list = data.stream().map(o -> (JSONObject) o).collect(Collectors.toList());
Example 2: convert json to arraylist java
import java.lang.reflect.Type;
private void parseJSON() {
Gson gson = new Gson();
Type type = new TypeToken<List<ContactModel>>(){}.getType();
List<ContactModel> contactList = gson.fromJson(jsonString, type);
for (ContactModel contact : contactList){
Log.i("Contact Details", contact.id + "-" + contact.name + "-" + contact.email);
}
}