我正在通过我的自定义类改造arraylist。我通过扩展RealmObject将同一个类转换为领域。如何将整个jsonarray写入/更新到领域?
jsonarray:
[{"sno":"1","name":"a"},{"sno":"2","name":"b"},{"sno":"3","name":"c"},{"sno":"4","name":"d"},{"sno":"5","name":"e"}]
我的改装回调:
Callback<ArrayList<CustomModel>> callback);
改造代码:
@Override
public void success(ArrayList<CustomModel> mycustomListModel, Response response) {
realm.beginTransaction();
realm.copyToRealmOrUpdate(mycustomListModel);
realm.commitTransaction();
}
CustomModel.class
public class CustomModel extends RealmObject {
private String sno;
private String name;
public String getsno() {
return sno;
}
public void setsno(String sno) {
this.sno = sno;
}
public String getname() {
return name;
}
public void setname(String name) {
this.name = name;
}
}