1.数据格式,三层泛型嵌套
String str = {
"code": 0,
"data": {
"totalCount": 231,
"itemCount": 100,
"items": [{
"statTime": 2020010123,
"expose": 127812,
"click": 0,
"download": 98 "
}]
}
}
2.引入依赖包
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
3.使用GSON进行转化
Gson gson = new Gson();
xxxResponse<xxxPage<TotalDataDto>> response = gson.fromJson(str,new TypeToken<xxxResponse<xxxPage<TotalDataDto>>>(){}.getType());
这样就完成了多层嵌套转化!