1 // json演示序列化和反序列化 2 User user = new User(0,"测试","0000",1); 3 String str = JSON.toJSONString(user); 4 System.out.println(str); 5 String str1 = "{"uid":1,"uname":"发序列化","pwd":"123","iAdmin":1,}"; 6 User userF = JSON.parseObject(str1, User.class); 7 System.out.println(userF.getUname()); 8 User user1 = new User(0, "测试1", "1234", 0); 9 User user2 = new User(0, "测试2", "1234", 0); 10 User user3 = new User(0, "测试3", "1234", 0); 11 User user4 = new User(0, "测试4", "1234", 0); 12 User user5 = new User(0, "测试5", "1234", 0); 13 User user6 = new User(0, "测试6", "1234", 0); 14 User user7 = new User(0, "测试7", "1234", 0); 15 User user8 = new User(0, "测试8", "1234", 0); 16 List<User> list = new ArrayList<>(); 17 list.add(user1); 18 list.add(user2); 19 list.add(user3); 20 list.add(user4); 21 list.add(user5); 22 list.add(user6); 23 list.add(user7); 24 list.add(user8); 25 String arryF = "[{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试1"},{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试2"},{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试3"},{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试4"},{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试5"},{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试6"},{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试7"},{"uid":0,"isAdmin":0,"pwd":"1234","uname":"测试8"}] " + 26 ""; 27 System.out.println(JSON.toJSON(list)); 28 List<User> list2 = JSON.parseArray(arryF, User.class); 29 for(User u:list2) { 30 System.out.println(u.getUname()); 31 }