Dictionary 对成员'的模糊引用;下标';字典

Dictionary 对成员'的模糊引用;下标';字典,dictionary,swift3,Dictionary,Swift3,我得到这个错误: 当我试图获取状态时,对成员“subscript”的引用不明确 串入字典 我的代码是: do { let dictionary: Dictionary<NSObject, AnyObject> = try JSONSerialization.jsonObject(with: geocodingResultsData!, options: JSONSerialization.ReadingOptions.mutableContainers) a

我得到这个错误:

当我试图获取状态时,对成员“subscript”的引用不明确 串入字典

我的代码是:

do {         
    let dictionary: Dictionary<NSObject, AnyObject> = try JSONSerialization.jsonObject(with: geocodingResultsData!, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<NSObject, AnyObject>

    // Get the response status.

    let status = dictionary["status"] as! String // Here : Ambiguous reference to member 'subscript' 

    if status == "OK" {
        let allResults = dictionary["results"] as! Array<Dictionary<NSObject, AnyObject>>
        self.lookupAddressResults = allResults[0]

        // Keep the most important values.
        self.fetchedFormattedAddress = self.lookupAddressResults["formatted_address"]as! String
        let geometry = self.lookupAddressResults["geometry"] as! Dictionary<NSObject, AnyObject>
        self.fetchedAddressLongitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lng"] as! NSNumber).doubleValue
        self.fetchedAddressLatitude = ((geometry["location"] as! Dictionary<NSObject, AnyObject>)["lat"] as! NSNumber).doubleValue

        completionHandler(status: status, success: true)
    }
    else {
        completionHandler(status: status, success: false)
    }
} catch {
}
do{
让dictionary:dictionary=try JSONSerialization.jsonObject(使用:geocodingResultsData!,选项:JSONSerialization.ReadingOptions.mutableContainers)作为!dictionary
//获取响应状态。
将status=dictionary[“status”]设为!String//Here:对成员“subscript”的引用不明确
如果状态==“正常”{
将allResults=dictionary[“results”]设为!数组
self.lookupAddressResults=所有结果[0]
//保持最重要的价值观。
self.fetchedFormattedAddress=self.lookupAddressResults[“格式化的_地址”]为!字符串
让geometry=self.lookupAddressResults[“geometry”]as!Dictionary
self.fetchedaddress经度=((几何体[“位置”]as!字典)[“lng”]as!NSNumber)。doubleValue
self.fetchedAddressLatitude=((几何体[“位置”]as!字典)[“纬度”]as!NSNumber)。doubleValue
completionHandler(状态:status,success:true)
}
否则{
completionHandler(状态:status,success:false)
}
}抓住{
}

使用
[String:Any]
而不是
[NSObject:AnyObject]
。JSON键必须是
String
。并省略
mutableContainers
。Swift中根本不需要它。或者尝试将
让status=dictionary[“status”作为NSObject]作为!String