-- 4 Fastjson解析 --
快速FAST(比任何一款都快) 面向对象 功能强大(支持普通JDK类任意java bean Class,Collection,Map,Date或者enum) 零依赖(只需要有JDK即可) 支持注解,全类型序列化
implementation 'com.alibaba:fastjson:1.2.76'
public class FastjsonUse { public static void main(String[] args) throws Exception { Student student = new Student(); student.setName("HongKong Doll"); student.setSex("女"); student.setAge(26); List<Course> courses = new ArrayList<>(); courses.add(new Course("Art", 100)); courses.add(new Course("Love", 99)); student.setCourses(courses); //序列化 生成json File file = new File("json/fastjson.json"); FileOutputStream fos = new FileOutputStream(file); JSONObject.writeJSONString(fos, student); //反序列化 json转JavaBean FileInputStream fis = new FileInputStream(file); Student student1 = JSONObject.parseObject(fis, Student.class); System.out.println(student1); }}
本文地址:IT问答频道 https://www.eeeoo.cn/itwenda/903299_3.html,嗨游网一个专业手游免费下载攻略知识分享平台,本站部分内容来自网络分享,不对内容负责,如有涉及到您的权益,请联系我们删除,谢谢!