parsing - 使用改造解析泛型类型列表
问题描述
我们使用改造、OkHttp 和 Gson 连接到我的 android 应用程序中的 API。
我们有一个带有以下响应的 API:
{
inputs: [
{
type: "A",
content:{
....
},
type: "B",
content:{
....
},
type: "C",
content:{
....
}
}
]
}
这些输入项是通用的,它们的类型是我在项目中拥有的静态类型之一。我已经有 5 种不同类型的内容(A、B、C、D、E)。
这是我上面 API 模型的数据类
data class inputs<T>(){
@SerializedName("type")
val type: String,
@SeializedName("content")
val content: T
}
如何将此 API 解析为这个通用输入数据类?
解决方案
推荐阅读
- aframe - A-Frame“开始体验”按钮
- ruby-on-rails - 在相关集合上使用 send()
- javascript - 使用 TypeORM 迁移如何在迁移期间为列播种
- scala - 在 Scala 中使用 For Comprehension 在 If 测试后仅使用 flatMap Future[T]
- c# - 使用实体框架从多对多关系中选择数据
- mocha.js - mocha chai 如何根据条件添加自定义标题
- php - 为什么 .env 文件中的值是空的?
- python - 我可以向新创建的用户的辅助电子邮件发送新帐户通知吗?
- android - LeakCanary 构建失败,构建类型不是调试或发布
- audio - 如何使用 VLC 命令行转换和规范化音频?