gpt4 book ai didi

android - 无法在 Realm.io 中处理 RealmList>

转载 作者:搜寻专家 更新时间:2023-10-30 23:39:21 25 4
gpt4 key购买 nike

我的 JSON 数据从服务器 api 看起来像这样

{
//...
PredecessorIds:[[1,2][3,4][5]]
//...
}

我可以通过 RealmList<RealmInt> 成功处理 Integer 或 String 数组但这次我因错误而失败,因为不支持 RealmList> 说 "Type parameter 'io.realm.realmList' is not within its bounds...."

对于 RealmIntthis link .

我尝试使用 RealmList<RealmLista> 来解决它其中 RealmLista 从 RealmObject 延伸并且有一个 RealmList像这样

public class RealmLista extends RealmObject {
public RealmList<RealmInt> value;
public RealmLista() {
}

public RealmLista(RealmList<RealmInt> val) {
this.value = val;
}

然后创建了一个RealmListaTypeAdapter并将其添加到 Gson 但是在反序列化时 Gson expects an Object (RealmLista) but is found array ,因为上面显示的服务器数据是显而易见的。

//RealmListAdapter for Gson
@Override
public RealmLista read(JsonReader in) throws IOException {
RealmLista lista = new RealmLista();
Gson gson = new Gson();
//how to read that [[1],[3,4]] int into RealmLista
in.beginArray();
while (in.hasNext()) {
lista.value.add(new RealmInt(in.nextInt()));
}
in.endArray();
return lista;
}

有没有办法存储一个简单的 List<List<Integer>>通过转换为 RealmObject保存时的任何类型,List<List<Integer>>很容易被Gson转换。 :-/

最佳答案

Realm 目前不支持列表列表。参见 https://github.com/realm/realm-java/issues/2549 .

所以@EpicPandaForce 关于创建一个包含内部列表的 RealmObject 的想法可能是最好的解决方法。

它可能看起来像这样:

public class Top extends RealmObject {
private RealmList<ChildList> list;
}

public class ChildList extends RealmObject {
private RealmList<RealmInt> list;
}

public class RealmInt extends RealmObject {
private int i;
}

要点的正确链接应该是:https://gist.github.com/cmelchior/1a97377df0c49cd4fca9

关于android - 无法在 Realm.io 中处理 RealmList<RealmList<RealmInt>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36983050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com