Navamani Samuel Navamani Samuel - 6 months ago 68
Java Question

How to Create JSONArray for a List<Class name>

I have a class called

class Student {
String name;
String age;

I have a method that returns List object like

public List<Student> getList(){

List<Student> li =new ArrayList();

li.add(new Student('aaa','12'));

return li;

I need to convert that list into JSONArray like this


Can anyone help me to get this? Thanks in Advancee..


I think you need not download the jettison jar file.

Using JSONArray and JSONObject you can easily convert that list into JSON object like @Juniad answer