我收到一个json
对象,格式为
"type":[{"id":"926"}]
我用Anyobject
类型
@NSManaged var type: AnyObject?
我想把它投到字典
if let t = type as? Dictionary<String, AnyObject> {
print(t["id"])
}
但是演员表示没有成功,而且t仍然总是零
答案 0 :(得分:1)
json响应中“type”的值是一个字典数组,因此您应该相应地解析它。
if let t = type as? [[String:AnyObject]] {
if let id = t.first?["id"] as? String {
print(id)
}
}