我在Swift 3中遇到了这个问题
我有以下代码:
do{
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : AnyObject]
if let datasFromJson = json["blog"] as? [[String:AnyObject]] {
for dataFromJson in datasFromJson{
if let title = dataFromJson("title")! as? String {
article.author = author
}
self.articles?.append(article)
}
}
当我尝试将标题转换为字符串
时出现此错误答案 0 :(得分:0)
错字(括号,而不是括号):
dataFromJson["title"] as? String // no exclamation mark after the closing bracket
注意:
.mutableContainers
在Swift中没用。[String:Any]
title
?或者是另一个错字title
与author
?