{
"result": "success",
"response_code": 200,
"message": "data list",
"data": [
{
"Assigned": "14",
"Closed": "150",
"Escalated TTO": "102",
"Escalated TTR": "2",
"New": "44",
"Pending": "4",
"Resolved": "14"
}
]
}
上面是我想要解析的响应,但我不想为它创建一个静态的POJO。模型应该是动态的,这样即使在上面的响应中有另一个键值对,如下图所示,响应也可以被解析,我想使用HashMap
是可能的。
{
"result": "success",
"response_code": 200,
"message": "data list",
"data": [
{
"Assigned": "14",
"Closed": "150",
"Escalated TTO": "102",
"Escalated TTR": "2",
"New": "44",
"Pending": "4",
"Resolved": "14",
"xx": "xx",
"xx": "xx",
"xx": "xx",
}
]
}
正如评论中所讨论的,理想的场景是Map<String, String>
。模型可能看起来像(假设你使用的是Gson。其他模型应该类似(:
data class ApiResponse(
@SerializedName("result")
val result: String,
@SerializedName("responseCode")
val responseCode: Int,
@SerializedName("message")
val message: String,
@SerializedName("data")
val data: List<Map<String, String>>
)