首页 > 编程语言 > 详细

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

时间:2015-06-30 12:23:59      阅读:255      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!