【发布时间】:2018-02-14 09:52:42
【问题描述】:
我在这里搜索了一些小例子来展示如何在 SwiftyJSON 中搜索 json 元素。我有以下 json 结构,有人可以给我技术吗?谢谢。
var jsonData = {
"css":[
{
"path": "style.css",
"updated": "12432"
},
{
"path": "base.css",
"updated": "34627"
}
],
"html":[
{
"path": "home.htm",
"updated": "3223"
},
{
"path": "about",
"updated": "3987"
}
]
}
我想搜索“html”->“home.htm”行。如何为它使用过滤方法。
对于简单的 json 结构,我得到了这样的示例,但就我而言,我不知道。
{
countryid : "1"
name : "New York"
},
{
countryid : "2"
name : "Sydeny"
}
if let array = arrCountry.arrayObject as? [[String:String]],
foundItem = array.filter({ $0["name"] == "def"}).first {
print(foundItem)
}
【问题讨论】:
-
您想在您提供的 JSON 中搜索
html和home.htm的值吗?所以你正在寻找updated值? -
是的,我想快速搜索“home.htm”并获取“更新”值。这是因为我有另一个 json 数据相同的结构来比较这个元素存在并比较“更新”值
标签: ios json swift3 swifty-json