Java 如何在将数据存储到数据库领域之前编辑数据

Java 如何在将数据存储到数据库领域之前编辑数据,java,android,json,realm,Java,Android,Json,Realm,有一段时间我遇到了一个问题,在将数据存储到数据库之前,我需要更改来自JSON的数据。我做了一些工作,但我只找到了最后一个元素,其他元素都被覆盖了,我如何才能得到所有的数据 public void setImage(String image) { ListUrl listUrl=new ListUrl(); this.image = image; if (!image.isEmpty()) { try { String paths=

有一段时间我遇到了一个问题,在将数据存储到数据库之前,我需要更改来自JSON的数据。我做了一些工作,但我只找到了最后一个元素,其他元素都被覆盖了,我如何才能得到所有的数据

public void setImage(String image) {
    ListUrl listUrl=new ListUrl();
    this.image = image;
    if (!image.isEmpty()) {

        try {
          String  paths= listUrl.Download_images(image);
            if (!paths.isEmpty()) {
                 illustration = new Illustration(image, paths, "", "", true);


              illustration.setPath(paths);
              illustration.setLink(image);
               illustration.setDownloaded(true);
              setIllustration(illustration);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
listUrl以获取图像的路径。它工作正常,所以我不知道问题出在哪里

public class Illustration extends RealmObject {

@PrimaryKey
private int id;

private String link;
private String path;
private String fullLink;
private String fullPath;
private int originalHeight;
private int originalWidth;
private boolean downloaded;

//getter和setter

不清楚如何保存数据。setIllustration做什么()?另外,如果只保存最后一个元素,听起来可能所有元素都有相同的主键,因此会相互覆盖。谢谢,但首先我保存了图中的路径和图像,对于保存数据库中的路径和图像的数据的设置说明,您是对的,我找到了相同的主键,所以我从类模型图中删除了@Primary key,发现每次运行都会重复数据,我希望你们现在能理解我的问题,因为我不需要只存储数据!您应该看看
Realm.copyToRealmOrUpdate()
方法。