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

时间:2016-10-06 09:04:52

标签: dictionary swift3

我收到此错误:

  

对成员'下标'"的模棱两可的提及当我试图获得状态   字符串到字典

我的代码是:

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 {
}

0 个答案:

没有答案