Navamani Samuel Navamani Samuel - 3 years ago 129
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..

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download