【发布时间】:2019-02-12 05:07:03
【问题描述】:
我正在尝试过滤其中包含数组和字典的数组。我想根据服务的类型进行过滤,然后在属性数组下其 isPrimaryMailbox 为 Yes。 这就是我所做的:-
let services = Manager.realm().objects(Service.self).filter("type = %@", "MAILBOX")
let serviceWithPrimaryEmail = services.filter({$0.attributes.first?.value == "Yes"})
但这显示了 isPrimaryMailbox 值为 No 的数据
以下是 json 响应:-
{
"data": {
"cust": [
{
"customerId": "2040349110",
"serv": [
{
"bill": "2010007656959",
"services": [
{
"type": "MOBILE",
"status": "ACTIVE",
"plan": {
"name": "Mobil"
},
"addOns": [
{
"status": "Active"
}
],
"hardware": [
{
"type": "HANDSET"
}
]
},
{
"type": "MOBILE",
"plan": {
"name": "Mobile Service"
},
"addOns": [
{
"status": "Active"
}
],
"hardware": [
{
"type": "HANDSET",
}
]
},
{
"type": "MAILBOX",
"plan": {
"name": "Service"
},
"attributes": [
{
"name": "mailboxSize",
"value": "1 GB"
},
{
"name": "isPrimaryMailbox",
"value": "Yes"
}
]
},
{
"type": "MAILBOX",
"status": "ACTIVE",
"plan": {
"name": "Service"
},
"attributes": [
{
"name": "mailboxSize",
"value": "1 GB"
},
{
"name": "isPrimaryMailbox",
"value": "No"
}
]
}
]
}
]
}
]
}
}
【问题讨论】:
-
什么是
services对象。您要过滤的字典。 -
你总是考虑第一个属性,你必须重新过滤 $0.attributes 以返回 isPrimaryMailbox 然后检查它的值。
-
我无法理解你的问题。
-
是否有公共 api 来获取这个 json ?
-
@s3cretshadow 现在我正在使用本地 json 文件。
标签: ios arrays swift filter realm