zoukankan      html  css  js  c++  java
  • 十一、fastjson

    fastjson

    fastjson 是阿里巴巴的开源JSON解析库,它可以解析 JSON 格式的字符串,支持将 Java Bean 序列化为 JSON 字符串,也可以从 JSON 字符串反序列化到 JavaBean

    依赖

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.62</version>
    </dependency>
    

    使用方法

    如:Student为java对象
    //java对象(集合)转换json字符串
    String str=JSON.toJSONString(Student);
    String str=JSON.toJSONString(stuList);
    //json字符串转换java对象
    Student stu=JSON.parseObject(str1,Student.class);
    
    //json字符串转换json对象
    JSONObject obj=JSON.parseObject(jsonStr);
    //json对象转换json字符串
    String jsonStr=JSON.toJSONString(jsonObject);
    
    //java对象转换json对象
    JSONObject jsonObject=(JSONObject)JSON.toJSON(Student);
    //json对象转换java对象
    Student student=JSON.toJavaObject(jsonObject, Student.class);
    
    //java对象集合转换json对象集合
    JSONArray jsonArrays=(JSONArray)JSON.toJSON(stulist);
    //json对象集合转换java对象集合
    List<Student> myList=new ArrayList<>();
    for(int i=0;i<jsonArrays.size();i++){
    Student student3=JSON.toJavaObject(jsonArrays.getJSONObject(i), Student.class);
            myList.add(student3);
    }
    
  • 相关阅读:
    fastlane
    OSI 模型
    iOS面试—0、技术点
    Git 提交规范
    iOS Aggregate 合并静态库
    iOS 应用分发平台
    json 转swift的工具
    敏捷开发
    mac 打包dmg
    iOS 获取素材
  • 原文地址:https://www.cnblogs.com/bigfairy/p/14002106.html
Copyright © 2011-2022 走看看