zoukankan      html  css  js  c++  java
  • 用fastjson处理json数据

     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         }
  • 相关阅读:
    Java中使用Base64编码URL
    JSON Web Token (JWT)入门学习
    1047. 删除字符串中的所有相邻重复项
    1021. 删除最外层的括号
    使用shell获取随机端口<帮你解决端口的占用烦恼>
    初始化一个vue项目并生成完整的目录结构
    mysql-常用字符函数
    设计模式-单例模式-饿汉和懒汉
    Java-指令的重排序
    Java-反射类加载到内存分析
  • 原文地址:https://www.cnblogs.com/lingdu9527/p/11022301.html
Copyright © 2011-2022 走看看