zoukankan      html  css  js  c++  java
  • jackson

     <!--Jackson required包-->
    
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.10.3</version>
            </dependency>
     // 第1步:创建ObjectMapper对象。
            // 创建ObjectMapper对象。它是一个可重复使用的对象。
            ObjectMapper mapper = new ObjectMapper();
            String jsonString = "{"name":"Mahesh", "age":21}";
    
            // 第2步:反序列化JSON到对象。
            // 从JSON对象使用readValue()方法来获取。通过JSON字符串和对象类型作为参数JSON字符串/来源。
            //map json to student
            Student student = mapper.readValue(jsonString, Student.class);
            System.out.println(student);
    
            // 第3步:序列化对象到JSON。
            // 使用writeValueAsString()方法来获取对象的JSON字符串表示。
            jsonString = mapper.writeValueAsString(student);
            System.out.println(jsonString);
  • 相关阅读:
    第二天续
    使用git提交本地仓库每次需要输入账号密码的问题解决
    第二天
    开启远程之路
    第一天
    第一步了解并且安装配置
    6
    Algorithms
    Algorithms
    Algorithms
  • 原文地址:https://www.cnblogs.com/yanjy/p/14635388.html
Copyright © 2011-2022 走看看