Android 利用 gson 将 json 转成 对象object 集合list

 

 

1、build.gradle 中引入gson

compile 'com.google.code.gson:gson:2.8.5'

 

2、将后台返回的json数据转对象、List。时间格式与后台返回的时间字符串一致,可直接转成Date类型

Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
// 转list
List<MyObject> myObject = gson.fromJson(data, new TypeToken<List<MyObject>>() {}.getType());

 

posted @ 2018-11-30 14:42  cralor  阅读(6295)  评论(0编辑  收藏  举报