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()); } }