fastjson转化复杂javabean

package json.fastjson;import java.util.ArrayList;import java.util.List;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;import com.alibaba.fastjson.serializer.SerializerFeature;public class Fastjson2JavaBean { public static void main(String[] args) { Course math = new Course(1,"数学"); Course english = new Course(2,"英语"); List<Course> courseList = new ArrayList<Course>(); courseList.add(math); courseList.add(english); Student student = new Student("zz",courseList); String json = JSONObject.toJSONString(student,SerializerFeature.WriteMapNullValue); System.out.println(json); Student s = JSON.parSEObject(json,Student.class); System.out.println(s.getName()); List<Course> list = s.getCourse(); for(int i = 0; i < list.size(); i++){ Course c = list.get(i); System.out.println(c.getId() + "--" + c.getName()); } }}class Student{ private String name; private List<Course> course; public Student(){ } public Student(String name,List<Course> course){ this.name = name; this.course = course; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<Course> getCourse() { return course; } public void setCourse(List<Course> course) { this.course = course; }}class Course{ private int id; private String name; public Course(){ } public Course(int id,String name){ this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; }}

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...