使用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的转换
原文地址:https://www.cnblogs.com/xtuxiongda/p/9745738.html