添加依赖:
implementation 'com.google.code.gson:gson:2.8.5'
将json解析为List集合
Type type = new TypeToken<List<TodayStepData>>() {}.getType();
List<TodayStepData> list = mGson.fromJson(stepArray, type);
将json解析为带泛型的实体类
String result = response.body().string();
Type type = new TypeToken<ResultEntity<List<SearchEntity>>>() {}.getType();
final ResultEntity<List<SearchEntity >> entity = new Gson().fromJson(result, type);
网友评论