fastjson List<> 转Json , Json 转List<>

转自:https://www.cnblogs.com/xiaohouzai/p/8972286.html

SerializeWriter:相当于StringBuffer

JSONArray:相当于List

JSONObject:相当于Map

JSON反序列化没有真正数组,本质类型都是List

 

 

比如说List

List转Json

List students = new ArrayList();
String str = JSON.toJSONString(students); // List转json

Json 转List 方法一

String json = ""; //获取的Json数据
List students = JSON.parseObject(json,new TypeReference<List>(){}); // Json 转List

Json 转List方法二

List students = JSON.parseArray(json,Student.class); 

 

Student 对象要实现Serializable接口

import java.io.Serializable;  
  
 
public class Student implements Serializable{ 

借鉴大佬文章装逼下:https://www.tuicool.com/articles/zUbQfa

你可能感兴趣的:(fastjson List<> 转Json , Json 转List<>)