- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在 Doctor 类中,我有 RealmList - specializationList。
public class Doctor extends RealmObject {
@PrimaryKey
private String doctorId;
private FullName fullName;
private Age age;
private String organizationId;
private Position position;
private String category;
private String loyalty;
private RealmList<Specialization> specializationList;
private Contacts contacts;
private String key;
....
专精类
public class Specialization extends RealmObject{
private String specializationName;
...
医生 JSON:
[
{
"doctorId": "7d8e72d7-809b-4273-9a3f-fa21718dee7f",
"doctorFullName": {
"firstName": "FirstName0",
"lastName": "LastName0",
"middleName": "MiddleName0"
},
"doctorPosition": {
"positionName": "PositionName0",
"department": "Department0"
},
"organizationId": "7cfaf5c0-127a-4cfc-b73b-52a35fd02ffd",
"specializations": [
{
"specializationName": "Specialization name 3"
},
{
"specializationName": "Specialization name 2"
},
{
"specializationName": "Specialization name 1"
}
],
"key": "firstname0 middlename0 lastname0"
}
]
使用 createOrUpdateAllFromJson 方法解析 JSON:
realm.createOrUpdateAllFromJson(Doctor.class, json);
我想做的是从 doctor 对象获取 RealmList:
RealmList<Specialization> specializationList = doctor.getSpecializationList();
但是 specializationList 的大小为 0。
Realm 文档:一些 JSON API 将返回 原始 类型的数组,例如整数或字符串,Realm 尚不支持。
可以使用 createOrUpdateAllFromJson 解析 JSON 数组(特化)吗?
最佳答案
是的,Realm 应该能够解析它,但看起来你的命名不正确。您的 Doctor 类将其称为 specializationList
,但在您的 JSON 中它是 specializations
。
如果您将 Doctor 类更改为以下内容,它应该可以工作:
public class Doctor extends RealmObject {
@PrimaryKey
private String doctorId;
private FullName fullName;
private Age age;
private String organizationId;
private Position position;
private String category;
private String loyalty;
private RealmList<Specialization> specializations;
private Contacts contacts;
private String key;
....
关于android - Realm.IO - 可以使用 createOrUpdateAllFromJson 解析 JSON 数组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30234343/
Java版的Realm有一个非常有用的方法: createOrUpdateAllFromJson(RealmObject,JSONArray) 它接受一个 JSON 对象数组,并将它们全部保存在数据库
我很高兴在开发中的 Android 应用程序中使用 realm Java。我从服务器 API 接收到 JSONObject 数组,realm 通过主要 realm 实例对象上方便的 createOrU
在 Doctor 类中,我有 RealmList - specializationList。 public class Doctor extends RealmObject { @Primar
我是一名优秀的程序员,十分优秀!