我使用realm来解析这个JSON,但是我收到了这个错误: java.lang.IllegalArgumentException:JSON对象没有主键字段' id'。
这是我的方法:
Realm r = Realm.getDefaultInstance();
r.beginTransaction();
r.createOrUpdateObjectFromJson(Application.class,result);
r.commitTransaction();
我的Application类是:
public class Application extends RealmObject {
@PrimaryKey
private int id;
private RealmList<girl> girls;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public RealmList<girl> getGirls() {
return girls;
}
public void setGirls(RealmList<girl> girls) {
this.girls = girls;
}
public Application() {
}
public Application(int id, RealmList<girl> girls) {
this.id = id;
this.girls = girls;
}
}
我班上的女孩是
public class girl extends RealmObject {
@PrimaryKey
private int id;
private String name;
private String ville;
private String tel;
private String photo;
//getters and setters and constructors with and without params
}
答案 0 :(得分:-2)
尝试使用realm.copyFromRealm();
以及更多参考下面的链接