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

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

相关文章:

  • 2022-01-02
  • 2021-12-23
  • 2021-12-30
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2021-07-10
  • 2022-12-23
  • 2021-12-23
  • 2022-01-03
  • 2022-02-03
相关资源
相似解决方案