1. 首先引入jar包 在pom.xml文件里加入下面依赖: <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.51</version> </dependency> 2. 创建一个Person类(方面下面使用) public class Person implements Comp…
1.需要用到的包 2.实例 实体类 people package com.shore.entity; /** * @author DSHORE/2019-4-19 * */ public class People { private int pid; private String pname; private int age; private String job; private double sal; public People() { } public People(int pid, St…
public class Test { public static void main(String[] args) { // 实现java对象与Json字符串之间的转化 // 1. Person对象与json之间的转换 //1.1 将Person对象转成json Person p = new Person(10, "张三"); Object obj = JSONArray.toJSON(p); String json = obj.toString(); System.out.prin…