zoukankan      html  css  js  c++  java
  • 使用fastjson对json串和对象的转换

    String转对象,数组

     1 String json = "{"code":"200","data":{"total":4,"list":[{"createBy":"admin","createTime":"2019-09-16 10:18:47","id":2,"params":{},"ruleName":"规则1","workBegintime":"08:00:00","workEndtime":"09:00:00","workoffBegintime":"18:00:00","workoffEndtime":"19:00:00"},{"createBy":"admin","createTime":"2019-09-16 17:27:15","id":5,"params":{},"ruleName":"考勤test2","workBegintime":"07:00:00","workEndtime":"08:20:35","workoffBegintime":"17:20:35","workoffEndtime":"18:20:35"}]}}";
     2         String json2 = "[{"第0名":0},{"第1名":1},{"第2名":2},{"第3名":3},{"第4名":4},{"第5名":5},{"第6名":6},{"第7名":7},{"第8名":8},{"第9名":9}]";
     3         Map map = JSON.parseObject(json, Map.class);
     4         List<Map> maps = JSON.parseArray(json2, Map.class);
     5         System.out.println(map);
     6         System.out.println(maps);
     7         String[] arr = new String[5];
     8         arr[0] = "1";
     9         arr[1] = "2";
    10         arr[2] = "3";
    11         System.out.println(ArrayUtil.arrayToString(arr));
    //代码执行结果
    {code=200, data={"total":4,"list":[{"createBy":"admin","workBegintime":"08:00:00","workoffEndtime":"19:00:00","createTime":"2019-09-16 10:18:47","workoffBegintime":"18:00:00","ruleName":"规则1","id":2,"params":{},"workEndtime":"09:00:00"},{"createBy":"admin","workBegintime":"07:00:00","workoffEndtime":"18:20:35","createTime":"2019-09-16 17:27:15","workoffBegintime":"17:20:35","ruleName":"考勤test2","id":5,"params":{},"workEndtime":"08:20:35"}]}} [{第0名=0}, {第1名=1}, {第2名=2}, {第3名=3}, {第4名=4}, {第5名=5}, {第6名=6}, {第7名=7}, {第8名=8}, {第9名=9}] 1 2 3

    对象转String字符串

  • 相关阅读:
    自定义TabBarController
    UITabBarController剖析
    IOS中UIScrollView的contentSize、contentOffset和contentInset属性
    iOS开发 剖析网易新闻标签栏视图切换
    transitionFromViewController方法的使用
    ViewController生命周期
    1816. Truncate Sentence
    1290. 二进制链表转整数
    1302. 层数最深叶子节点的和
    102.二叉树的层次遍历
  • 原文地址:https://www.cnblogs.com/mikemhm/p/11556256.html
Copyright © 2011-2022 走看看