How to convert json to ArrayList object in Java? [duplicate] How to convert json to ArrayList object in Java? [duplicate] json json

How to convert json to ArrayList object in Java? [duplicate]


You need to use:

Product p = new Product(); p.setId( jsonArray.getJSONObject(i).getInt("id") );p.setName( jsonArray.getJSONObject(i).getString("name") );list.add(p)

All inside the loop, because you need to create a new product each time.