码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript学习记录总结(五)——servlet将json数据写出去

时间:2015-06-30 12:24:28      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

定义teacher和student实体  

json.do

    List<Student> stus=new ArrayList<Student>();
        stus.add(new Student("zsf1"));
        stus.add(new Student("zsf2"));
        stus.add(new Student("zsf3"));
        stus.add(new Student("zsf4"));
        Teacher teacher=new Teacher();
        teacher.setName("chj");
        teacher.setAge(28);
        teacher.setBirth(new Date(1988,1,12));
        teacher.setSex("男");
        teacher.setStudents(stus);
        JSONObject json=JSONObject.fromObject(teacher);
        
        response.getOutputStream().write(json.toString().getBytes());
        response.setContentType("application/json");

结果如下

{"age":28,"birth":{"date":12,"day":0,"hours":0,"minutes":0,"month":1,"seconds":0,"time":60529824000000,"timezoneOffset":-480,"year":1988},"name":"chj","sex":"男",
"students":[{"name":"zsf1"},{"name":"zsf2"},{"name":"zsf3"},{"name":"zsf4"}]}

JavaScript学习记录总结(五)——servlet将json数据写出去

标签:

原文地址:http://www.cnblogs.com/ly-radiata/p/4424968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!