zoukankan      html  css  js  c++  java
  • fastJSON 使用总结

    1.介绍Fastjson

    Fastjson是一个Java语言编写的JSON处理器。

    如果获得Fastjson?
    https://github.com/alibaba/fastjson

    2.使用Fastjson

     Json互转List<T>

    比如说List<Strudent>
    List转Json
    
    List<Student> students = new ArrayList();
    String str = JSON.toJSONString(students); // List转json
    Json 转List 方法一
    
    String json = ""; //获取的Json数据
    List<Student> students = JSON.parseObject(json,new TypeReference<List<Student>>(){}); // Json 转List
    Json 转List方法二( 一般用方法二)
    
    List<Student> students = JSON.parseArray(json,Student.class); 
    

      

    对象与字符串互转
    将对象转换成为字符串
    String str = JSON.toJSONString(infoDo);
    字符串转换成为对象
    Student student = JSON.parseObject(str, Student.class);
    

     

    字符串互转JSONObject

    String 转 Json对象
    JSONObject jsonObject = JSONObject.parseObject(jsonString);
    
    json对象转string
    String jsonString = jsonObject.toJSONString();

     

    map与字符串之间互转

      //字符串转map
      JSONObject  jsonObject = JSONObject.parseObject(str);
      Map<String,Object> map = (Map<String,Object>)jsonObject;//    //json对象转Map
      //map转字符串
      String jsonString = JSON.toJSONString(map);
    

     

    Map 转 Json对象

       //map转json对象
        Map<String,Object> map = new HashMap<>();
        map.put("age", 24);
        map.put("name", "cool_summer_moon");
        JSONObject json = new JSONObject(map);
      //json对象转Map 
      Map<String,Object> map = (Map<String,Object>)jsonObject; 
    

      

  • 相关阅读:
    [转]人生哲理小故事
    取PE文件OriginalFilename解析VERSION资源
    [转]COM对象创建外部机制
    读书的几个步骤
    zoj 2412 Farm Irrigation
    HDU 1575 Tr A
    toj 2843 Diamonds
    HDU 1856 More is better
    toj 2841 Bitwise Reverse
    hdu 1213 How Many Tables
  • 原文地址:https://www.cnblogs.com/qqfff/p/12795820.html
Copyright © 2011-2022 走看看