【发布时间】:2022-01-23 10:05:42
【问题描述】:
我在服务器上有一个数据库(MySql)和一个本地数据库(Room),在服务器上的数据库中有一个名为 countries 的表,在该表内部,有一个名为 countryName 的列和该列的类型是 JSON,如下图所示。
countryName里面的内容是JSONObject
表格
@Entity(tableName = "Countries")
public class Country {
private JSONObject countryName;
public Country(JSONObject countryName) {
this.countryName = countryName;
}
public JSONObject getCountryName() {
return countryName;
}
}
错误
Cannot figure out how to save this field into database. You can consider adding a type converter for it.
如何使用 Room 创建 JSONObject 列?
【问题讨论】:
-
Json 对象无法保存到房间,转换为字符串并保存到房间并在检索字符串时再次转换,将完成工作。
-
@RaBaKa78 我知道,不过最好像服务器一样存储
标签: java android json android-room