将整个jsonarray添加到领域

时间:2016-03-30 16:34:45

标签: android realm

我正在通过我的自定义类改造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;
    }


}

0 个答案:

没有答案