背景
{
"status": 1,
"data": {
"id": 52,
"userName": "admin",
"createTime": "2021-11-03 15:12:46",
"updateTime": "2021-11-03 15:12:46"
},
"msg": "登录成功"
}
针对这种嵌套数据
解决
封装对象
import java.util.*
class UserVo {
var userId: Int? = null
var userName: String? = null
var createTime: String? = null
var updateTime: String? = null
}
package com.lettytrain.notesapp.vo
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
class ServerResponse <T>{
var status: Int = -1
var data: T? = null //status为0时,将返回的数据封装到data
var msg: String? = null //提示信息
}
需要依赖
implementation 'com.google.code.gson:gso