FastJson使用方法

FastJson是阿里的一款开源框架,用来快速实现Java的序列化和反序列化。

官方地址:https://github.com/alibaba/fastjson

使用方法演示:

下载jar包,使用IDEA导入fastjson.jar

import com.alibaba.fastjson.*;
class Student{
    private int age;
    private  String name;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
public class FastjsonTest {


    public static void main(String[] args) {
     
        Student s  = new Student();
        s.setAge(18);
        s.setName("haha");
        String jsonstring = JSON.toJSONString(s);
        System.out.println(jsonstring);
        Student s2 = (Student)JSON.parseObject(jsonstring,Student.class);
        System.out.println(s2.getAge());
        System.out.println(s2.toString());


    }

}
    

 

posted @ 2018-08-02 13:49  夜雨最萌  阅读(755)  评论(0编辑  收藏  举报