标签:bsp enc json int group sys system pom.xml div
1. pom.xml
<dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency>
2. JSON和对象/集合间的转换
public static void main(String[] args) { User user = new User(); user.setNickname("aaaa"); user.setPswd("bbb"); List<User> userList = new ArrayList<User>(); userList.add(user); // 对象 --> JSONObject / JSONArray JSONObject jsonObject = JSONObject.fromObject(user); System.out.println(jsonObject.toString()); JSONArray jsonArray = JSONArray.fromObject(userList); System.out.println(jsonArray.toString()); // JSONObject --> 对象 / JSONArray --> 集合 User user2 = (User) JSONObject.toBean(jsonObject,User.class); System.out.println(user2.getNickname()); User[] userArray = (User[]) JSONArray.toArray(jsonArray,User.class); System.out.println(userArray.length); }
标签:bsp enc json int group sys system pom.xml div
原文地址:https://www.cnblogs.com/yifanSJ/p/9220797.html