<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.49</version> </dependency>
JAVA对象转JSON对象
JSONObject jsonObject = (JSONObject)JSONObject.toJSON(student);
JAVA对象转JSON字符串
String jsonString = JSONObject.toJSONString(student);
JSON对象转JSON字符串
String jsonString = jsonObject.toJSONString(); String jsonString1 = JSONObject.toJSONString(jsonObject);
JSON字符串转JSON对象
JSONObject jsonObject = JSONObject.parseObject(jsonString);
JSON对象转JAVA对象
Student student = JSONObject.toJavaObject(jsonObject, Student.class);
JSON字符串转JAVA对象
Student student1 = JSONObject.parseObject(stuString, Student.class);
字符串转集合
List<NationalCityCode> provinceList = jsonObject.parseObject(provinces, new TypeReference<List<NationalCityCode>>() {});
字符串转化成对象
NationalCityCode province = jsonObject.parseObject(provinces, new TypeReference<NationalCityCode>() {});