fastjson的使用
Posted lingdu9527
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了fastjson的使用相关的知识,希望对你有一定的参考价值。
1 public static void main(String[] args) 2 // json演示序列化和反序列化 3 User user = new User(0,"测试","0000",1); 4 String str = JSON.toJSONString(user); 5 System.out.println(str); 6 String str1 = "\"uid\":1,\"uname\":\"发序列化\",\"pwd\":\"123\",\"iAdmin\":1,"; 7 User userF = JSON.parseObject(str1, User.class); 8 System.out.println(userF.getUname()); 9 User user1 = new User(0, "测试1", "1234", 0); 10 User user2 = new User(0, "测试2", "1234", 0); 11 User user3 = new User(0, "测试3", "1234", 0); 12 User user4 = new User(0, "测试4", "1234", 0); 13 User user5 = new User(0, "测试5", "1234", 0); 14 User user6 = new User(0, "测试6", "1234", 0); 15 User user7 = new User(0, "测试7", "1234", 0); 16 User user8 = new User(0, "测试8", "1234", 0); 17 List<User> list = new ArrayList<>(); 18 list.add(user1); 19 list.add(user2); 20 list.add(user3); 21 list.add(user4); 22 list.add(user5); 23 list.add(user6); 24 list.add(user7); 25 list.add(user8); 26 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\"]\r\n" + 27 ""; 28 System.out.println(JSON.toJSON(list)); 29 List<User> list2 = JSON.parseArray(arryF, User.class); 30 for(User u:list2) 31 System.out.println(u.getUname()); 32 33
以上是关于fastjson的使用的主要内容,如果未能解决你的问题,请参考以下文章