我有这个JSON:
{
cover = {
id = 1;
};
description = "Test"
place = {
id = 11;
location = {
city = Wheatley;
};
name = "Wheatley Provincial Park";
};
},
{
cover = {
id = 2;
};
description = "Cool"
place = {
id = 22;
location = {
city = Wheatley;
};
name = "Wheatley Provincial Park";
};
}
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
if let fbData = result as? [String : Any] {
print(fbData)
for events in fbData {
print (events["name"] as! String)
//this displays an error
//Type (Key: String, value: Any) has subscript members
}
Run Code Online (Sandbox Code Playgroud)
}
但我不知道如何循环它们
我已经尝试过这些解决方案,但它们从未奏效
if let array = result as? [String : AnyObject]{
if let fbData = array["data"] as? [[String : AnyObject]] {
print(fbData)
for event in fbData {
print (event["name"] as! String)
}
}
}
Run Code Online (Sandbox Code Playgroud)
result是 Any类型的[String : AnyObject]data并转换为字典数组 - [[String : AnyObject]].