• 生成JSON数据--fastjson(阿里)方法


    fastjson(阿里)方法生成JSON数据:

    与Gson类似,创建相应类,再使用JSON.toJSONString()添加对象
    

    要求:生成如下JSON数据

    1.{“age”:3,”name”:”zhangsan”,”sex”:true,”weight”:180}


    代码:

    package com.qf.demo7;
    
    import com.alibaba.fastjson.JSON;
    /**
     * Gson   toJson
     * FastJson   toJsonString
     * @author Administrator
     *
     */
    public class Test {
    
        public static void main(String[] args) {
            Person1 person = new Person1("zhangsan",true,3,180);
            String json = JSON.toJSONString(person);
            System.out.println(json);
        }
    }
    
    class Person1{
        private String name;
        private boolean sex;
        private int age;
        private int weight;
        public Person1(String name,boolean sex, int age,int weight) {
            super();
            this.name = name;
            this.sex = sex;
            this.age = age;
            this.weight = weight;
        }
        public Person1() {
            super();
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
    
        public int getWeight() {
            return weight;
        }
        public void setWeight(int weight) {
            this.weight = weight;
        }
        public boolean isSex() {
            return sex;
        }
        public void setSex(boolean sex) {
            this.sex = sex;
        }
        @Override
        public String toString() {
            return "Person [name=" + name + "sex = "+sex+", age=" + age + "]";
        }
    
    }
    
    
  • 相关阅读:
    ceph(4)--Ceph 的基础数据结构
    ceph(3)--Ceph 物理和逻辑结构
    ceph(2)--Ceph RBD 接口和工具
    ceph(1)--安装和部署
    Ceph中文文档
    Linux系统介绍(五)常用命令
    Linux系统介绍(四)IO重定向与管道
    剑指offer:跳台阶
    剑指offer:斐波那契数列
    剑指offer:旋转数组的最小数字
  • 原文地址:https://www.cnblogs.com/TCB-Java/p/6853998.html
Copyright © 2020-2023  润新知