zoukankan      html  css  js  c++  java
  • 生成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 + "]";
        }
    
    }
    
    
  • 相关阅读:
    UIScrollView
    xcode debug
    ios 开发小技巧
    xcode调试
    Objective-C的反射机制
    git 命令
    iOS block的一些理解
    iOS 开发常用宏
    iOS 常用函数
    转:支付宝系统架构(内部架构图)
  • 原文地址:https://www.cnblogs.com/TCB-Java/p/6853998.html
Copyright © 2011-2022 走看看