【问题标题】:How to convert JSON (or POJO) to Room Entity?如何将 JSON(或 POJO)转换为房间实体?
【发布时间】:2021-03-04 15:40:04
【问题描述】:

拥有简单的 JSON,for instance:

{
    "widget": {
        "debug": "on",
        "window": {
            "title": "Sample Konfabulator Widget",
            "name": "main_window",
            "width": 500,
            "height": 500
        },
        "image": { 
            "src": "Images/Sun.png",
            "name": "sun1",
            "hOffset": 250,
            "vOffset": 250,
            "alignment": "center"
        },
        "text": {
            "data": "Click Here",
            "size": 36,
            "style": "bold",
            "name": "text1",
            "hOffset": 250,
            "vOffset": 100,
            "alignment": "center",
            "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
        }
    }
}

我们可以使用sitesAndroid Studio 中的plugins 将其转换为POJO。但是如何转换成RoomEntities呢?

【问题讨论】:

  • @a_local_nobody,是的,但这是手动操作。我想要一个自动将 JSON 转换为实体的工具。

标签: android json entity android-room


【解决方案1】:

您可以只注释您的 POJO 来创建房间实体。有关此链接的更多信息,请查看官方文档https://developer.android.com/training/data-storage/room/defining-data

【讨论】:

  • 谢谢!是的,我们可以。
猜你喜欢
  • 1970-01-01
  • 2019-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多