轉自:https://www.cnblogs.com/xiaohouzai/p/8972286.html
SerializeWriter:相當於StringBuffer
JSONArray:相當於List<Object>
JSONObject:相當於Map<String, Object>
JSON反序列化沒有真正數組,本質類型都是List<Object>
比如說List<Strudent>
List轉Json
List<Student> students = new ArrayList(); String str = JSON.toJSONString(students); // List轉json
Json 轉List 方法一
String json = ""; //獲取的Json數據 List<Student> students = JSON.parseObject(json,new TypeReference<List<Student>>(){}); // Json 轉List
Json 轉List方法二
List<Student> students = JSON.parseArray(json,Student.class);
Student 對象要實現Serializable接口
import java.io.Serializable; public class Student implements Serializable{
借鑒大佬文章裝逼下:https://www.tuicool.com/articles/zUbQfa