gpt4 book ai didi

java - 如何在 android 中创建 RealmList>

转载 作者:太空狗 更新时间:2023-10-29 14:39:26 25 4
gpt4 key购买 nike

我正在尝试从服务器 (JSON) 中获取 RealmList 的 RealmList 到 Realm 对象中。我得到了

error: Element type of RealmList must be a class implementing 'RealmModel' or one of the 'java.lang.String', 'byte[]', 'java.lang.Boolean', 'java.lang.Long', 'java.lang.Integer', 'java.lang.Short', 'java.lang.Byte', 'java.lang.Double', 'java.lang.Float', 'java.util.Date'.

{
"facilities": [
{
"facility_id": "1",
"name": "Property Type",
"options": [
{
"name": "Apartment",
"icon": "apartment",
"id": "1"
},
{
"name": "Condo",
"icon": "condo",
"id": "2"
},
{
"name": "Boat House",
"icon": "boat",
"id": "3"
},
{
"name": "Land",
"icon": "land",
"id": "4"
}
]
},
{
"facility_id": "2",
"name": "Number of Rooms",
"options": [
{
"name": "1 to 3 Rooms",
"icon": "rooms",
"id": "6"
},
{
"name": "No Rooms",
"icon": "no-room",
"id": "7"
}
]
},
{
"facility_id": "3",
"name": "Other facilities",
"options": [
{
"name": "Swimming Pool",
"icon": "swimming",
"id": "10"
},
{
"name": "Garden Area",
"icon": "garden",
"id": "11"
},
{
"name": "Garage",
"icon": "garage",
"id": "12"
}
]
}
],
"exclusions": [
[
{
"facility_id": "1",
"options_id": "4"
},
{
"facility_id": "2",
"options_id": "6"
}
],
[
{
"facility_id": "1",
"options_id": "3"
},
{
"facility_id": "3",
"options_id": "12"
}
],
[
{
"facility_id": "2",
"options_id": "7"
},
{
"facility_id": "3",
"options_id": "12"
}
]
]
}

最佳答案

试试这个解决方案

public class Exclusion extends RealmObject {
private int facilityId;
private int optionsId;
}

public class Exclusions extends RealmObject {
private RealmList<Exclusion> exclusions;
}

所以现在您可以使用 RealmList<Exclusions> exclusionsRealmList作为 Realm 列表,合法

希望对你有帮助

关于java - 如何在 android 中创建 RealmList<RealmList<Object>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50976215/

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