package com.beijxing.TestMain;
import java.util.ArrayList;
import java.util.List;
import com.beijxing.entity.Student;
import net.sf.json.JSONArray;
/**
* List<Object>转换为JSONArray
* @author ywp
* @version 2016年10月23日21:36:08
*/
public class TestJson1 {
public static void main(String[] args) {
createJSONArray();
}
public static void createJSONArray(){
Student student = new Student();
student.setId(1);
student.setName("杨文培");
student.setSex("男");
//student.setAge(23);
student.setBirthday("1993-01-23");
List<String> list = new ArrayList<String>();
list.add("篮球");
list.add("乒乓球");
list.add("羽毛球");
student.setHobby(list);
Student student2 = new Student();
student2.setId(1);
student2.setName("杨文培");
student2.setSex("男");
//student.setAge(23);
student2.setBirthday("1993-01-23");
List<String> list2 = new ArrayList<String>();
list2.add("篮球");
list2.add("乒乓球");
list2.add("羽毛球");
student2.setHobby(list2);
List<Student> list3 = new ArrayList<Student>();
list3.add(student);
list3.add(student2);
JSONArray jsonArray = JSONArray.fromObject(list3);
System.out.println("jsonArray="+jsonArray);
}
}