对list类型的转化:
GSON gson = new GSON();
gson.fromJson(strJson, User.class); //对象转化
gson.fromJson(respDto.getOptions(), new TypeToken<List<Map<String, String>>>(){}.getType()); //list map 转化
或
GsonUtil.fromJson(test, MessageBasic2.class);
但是对于层级解析的问题,无法解决,比如我的json层级是3级,我只想解开1级,下面的用String代替。但是执行会报错。
String test="{"body":{"updateTime":"2021-01-18 13:57:34","state":"0"},"key":"STFZJX021","operType":"UPDATE"}"; GsonUtil.fromJson(test, MessageBasic2.class);
Caused by: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 1 column 10 path $.body
可以通过fastJson来解决层级问题。