获取格式奇怪的 NSDictionary 值
Getting weirdly formatted NSDictionary value
var nsarray:[NSMutableDictionary] = [["object":["uid":["age":"26","gender":"male"]]]]
print(nsarray[0]["object"])
看起来是这样的。我想获得值 "uid",所以当它打印时它只是 "uid"。当前正在打印:
"uid":["age":"26","gender":"male"]
I want to get the "uid" value. Meaning when it prints it is just "uid". "uid" is a placeholder for a unique ID so I won't know what the uid is.
看起来 "object"
键包含另一个字典,它只有一个元素。要获取第一个密钥,请调用 allKeys
获取密钥,将它们转换为 Array
,然后选择初始元素:
let d = nsarray[0]["object"] as! NSDictionary
print(Array(d.allKeys)[0])
var nsarray:[NSMutableDictionary] = [["object":["uid":["age":"26","gender":"male"]]]]
print(nsarray[0]["object"])
看起来是这样的。我想获得值 "uid",所以当它打印时它只是 "uid"。当前正在打印:
"uid":["age":"26","gender":"male"]
I want to get the "uid" value. Meaning when it prints it is just "uid". "uid" is a placeholder for a unique ID so I won't know what the uid is.
看起来 "object"
键包含另一个字典,它只有一个元素。要获取第一个密钥,请调用 allKeys
获取密钥,将它们转换为 Array
,然后选择初始元素:
let d = nsarray[0]["object"] as! NSDictionary
print(Array(d.allKeys)[0])