我有一个 SwiftyJson 对象。
我无法过滤那个数组。我试过这个解决方案 https://stackoverflow.com/a/37497170/4831567 .但是我的 json 格式不同,这就是为什么不起作用。
[
{
"name": "19860",
"header": {
"start_time": "1519270200",
"end_time": "1519299000",
"state": "lunch"
},
"alerts": "1",
"venue": {
"location": "Delhi, India",
"timezone": "+05:30"
},
"srs_category": [
0,
1
]
},
{
"name": "19861",
"header": {
"start_time": "1519270200",
"end_time": "1519299000",
"state": "Dinner"
},
"alerts": "1",
"venue": {
"location": "Mumbai, India",
"timezone": "+05:30"
},
"srs_category": [
1,
3
]
},
{
"name": "19862",
"header": {
"start_time": "1519270200",
"end_time": "1519299000",
"state": "lunch"
},
"alerts": "1",
"venue": {
"location": "Surat, India",
"timezone": "+05:30"
},
"srs_category": [
0,
2
]
}
]
我想找到 srs_category 包含 1 的对象。我知道可以通过循环和条件来实现。但我想通过 NSPredicate。如果可能,请帮助我。
谢谢。
最佳答案
这是使用 SwiftyJSON 的简单方法:
let filtered = JSON(yourArray).arrayValue.filter({
$0["srs_category"].arrayValue.map({ $0.intValue }).contains(1)
})
关于ios - 在 SwiftyJson 中过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48925619/