您可以使用 Swifty-JSON 搜索 JSON 吗?
Can you search JSON using Swifty-JSON?
我正在使用 SwiftyJSON 和一大块 JSON。使用 SwiftyJSON,是否可以使用唯一标识符搜索数据以检索其他对象?
例如。
{
"places": [
{
"name": "Place 1",
"id": 123,
},
{
"name": "Place 2",
"id": 456,
}
]
}
我想使用 id = 123
来获取关联名称。一旦 JSON 被加载,这就是全部。这可能吗?
这是来自 Github 上的 swifty JSON 文档:
//If json is .Dictionary
for (key: String, subJson: JSON) in json {
//Do something you want
}
第一个元素始终是字符串,即使 JSON 是数组
//If json is .Array
//The `index` is 0..<json.count's string value
for (index: String, subJson: JSON) in json {
//Do something you want
}
然后你可以只检查你的id是否等于123。然后你只需在循环中做一个循环,如果places["id"]=123,那么你就有了你的对象places。
我的意思是在算法中:
for(places in JSON)
{
if(places["id"] == 123)
{
//my object is object
}
}
我正在使用 SwiftyJSON 和一大块 JSON。使用 SwiftyJSON,是否可以使用唯一标识符搜索数据以检索其他对象?
例如。
{
"places": [
{
"name": "Place 1",
"id": 123,
},
{
"name": "Place 2",
"id": 456,
}
]
}
我想使用 id = 123
来获取关联名称。一旦 JSON 被加载,这就是全部。这可能吗?
这是来自 Github 上的 swifty JSON 文档:
//If json is .Dictionary
for (key: String, subJson: JSON) in json {
//Do something you want
}
第一个元素始终是字符串,即使 JSON 是数组
//If json is .Array
//The `index` is 0..<json.count's string value
for (index: String, subJson: JSON) in json {
//Do something you want
}
然后你可以只检查你的id是否等于123。然后你只需在循环中做一个循环,如果places["id"]=123,那么你就有了你的对象places。
我的意思是在算法中:
for(places in JSON)
{
if(places["id"] == 123)
{
//my object is object
}
}