fastjson Json中嵌套一个json数组

ep6jt1vc  于 2021-11-27  发布在  Java
关注(0)|答案(7)|浏览(435)

解析不了

92dk7w1h

92dk7w1h1#

嵌套的数组反序列号不了

cig3rfwq

cig3rfwq2#

{"data":[{"project_id":1,"project_name":"测试1"},{"project_id":2,"project_name":"测试2"},{"project_id":3,"project_name":"测试3"}],"errMsg":"","status":200},按道理序列号后,根据data的类型序列化为改类型的List,实际上[{"project_id":1,"project_name":"测试1"},{"project_id":2,"project_name":"测试2"},{"project_id":3,"project_name":"测试3"}]这个没有被反序列化,还是字符串存在的

5cg8jx4n

5cg8jx4n3#

不是很明白你的意思,能提供重现问题的testcase么?

6jygbczu

6jygbczu4#

{"data":[{"project_id":1,"project_name":"测试1"}],"errMsg":"","status":200},data只能被序列化为JSONArray,不能序列化为LIst data的类型的对象

xuo3flqw

xuo3flqw5#

CFSResult first = JSON.parseObject(text, first.getClass());

rryofs0p

rryofs0p6#

public class CFSResult implements Serializable{
private static final long serialVersionUID = -3487969361148363299L;
//数据
private T data;
//错误信息
private String errMsg;
//状态码
private int status;
}
CFSResult first = new CFSResult();
first = JSON.parseObject(text, first.getClass());
本来T我打算用一个List去反序列化的,可是发现不管什么类型是,T都只能是JSONArray,想要序列化为对应的data用类似的方法重新再序列化一次。

r7knjye2

r7knjye27#

CFSResult first = new CFSResult();
first = JSON.parseObject(text, first.getClass());
List data = JSON.parseArray(first.getData().toJSONString(), obj);
obj是T的class

相关问题