json - JSON响应中同一对象的字符串和布尔值
问题描述
我有一个“rest api”,它使我成为我的 CMS 插件,我在 android 中用于我的应用程序。
当图像存在时,它返回 a string
,当没有图像时,它返回 a boolean
。
如果图像存在,则在 json 中为:
{
"events":[
{
"id":4651,
"title":"Test title",
"description":"testttt",
"image": {
url: "https://myhost.tv/wp-content/uploads/2019/07/event2.jpg",
id: "4652"}
}
]
}
如果我的帖子没有图片,则json如下:
{
"events":[
{
"id":4652,
"title":"Test title 2",
"description":"testttt",
"image":false
}
]
}
我的recyclerview模型是:
data class EventosFeed(
val events: Array<Events>
)
data class Events (
val id : Int,
val title : String,
val image : Image? = null,
.
.
.
)
data class Image (
val url : String,
val id : Int,
)
如果帖子有图片,没问题,但如果我的帖子没有图片,我就有问题,因为它是模型中的字符串。模型如何解决这个问题。
解决方案
推荐阅读
- xamarin.forms - 为什么这个通用代码不适用于在 iOS 中显示 PDF 而不是在 Android 中?
- php - Amazon Linux EC2 上的 PHP 服务器
- java - 如何在 Netbeans 中使用 keycloak-installed-adapter 使用 keycloak.logout()
- r - 根据同一数据框的两列以上的值汇总一列的值
- amazon-web-services - 一个具有“较小功能”的 lambda 函数与多个函数的优缺点是什么
- c - 为什么while循环在else语句之前停止?
- flutter - 颤振:如何在按下后退按钮时不退出应用程序
- css - 导航到特定组件或刷新时如何将类添加到正文?
- google-apps-script - 谷歌搜索中的单字符点是什么意思?
- php - laravel 编辑表单复选框值旧输入