码迷,mamicode.com
首页 > Web开发 > 详细

使用json-org包实现POJO和json的转换

时间:2018-10-05 21:10:33      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:超级   -o   数组   pojo   pre   print   string   color   转换   

使用json-org包实现POJO和json的转换

这个jar包把对象转换成json超级舒服,所以顺便记录一下吧

把单个pojo对象转换成json对象

        Student student = new Student("2015551404","熊大");
        JSONObject object = new JSONObject(student);
        System.out.println(object.toString(2));

 

把多个pojo对象转成json数组

        Student student = new Student("2015551404","熊大");
        Student student1 = new Student("2015551405", "孙嘉宁");
        ArrayList<Student> list = new ArrayList<>();
        list.add(student);
        list.add(student1);
        JSONArray array = new JSONArray(list);
        System.out.println(array.toString(2));

 

使用json-org包实现POJO和json的转换

标签:超级   -o   数组   pojo   pre   print   string   color   转换   

原文地址:https://www.cnblogs.com/xtuxiongda/p/9745738.html

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