小编Koc*_*cio的帖子

How to check if key exists in swiftyJSON when json contain array with no keys

I know about swiftyJSON method exists() but it does not seem to work always as they say. How can I get proper result in this case below? I cannot change JSON structure because I am getting this through client's API.

var json: JSON =  ["response": ["value1","value2"]]
if json["response"]["someKey"].exists(){
    print("response someKey exists")
}
Run Code Online (Sandbox Code Playgroud)

Output:

response someKey exists

That shouldn't be printed because someKey does not exist. But sometimes that key comes from client's API, and i need to find out if …

json ios swift swifty-json

11
推荐指数
1
解决办法
9986
查看次数

标签 统计

ios ×1

json ×1

swift ×1

swifty-json ×1