【发布时间】:2020-11-29 10:43:12
【问题描述】:
在 Android 上使用 Room 库时,我发现自己处于以下情况,我正在尝试创建一个商店,但我需要插入金额和相应的项目。但是我不知道如何在房间中保存以下json格式,非常感谢您的帮助
[{
"id": 1,
"quantitiy": 3,
"item": {
"id": 1,
"name": "Huevos Frescampo X30",
"description": "Huevo Rojo A Insuperable, 30 Unidad(es). 1032680",
"price": 8950,
"createdAt": "2020-08-08T20:13:33",
"updatedAt": "2020-08-08T20:13:33"
}
}, {
"id": 2,
"quantitiy": 2,
"item": {
"id": 2,
"name": "Banano Criollo",
"description": "Banano Criollo",
"price": 630,
"createdAt": "2020-08-08T20:13:33",
"updatedAt": "2020-08-08T20:13:33"
}
}]
@Entity(tableName = "cart")
data class Cart (
@PrimaryKey
val id: Long,
val quantitiy: Long,
val item: ItemC
)
@Entity(tableName = "item")
data class ItemC (
val id: Long,
val name: String,
val description: String,
val price: Long,
val createdAt: String,
val updatedAt: String
)
【问题讨论】:
标签: android json sqlite android-room local-database