ios - Type Any 没有下标成员 Swift 3.0

标签 ios swift

尝试转换函数以使其与 Swift 3.0 兼容。必须将参数 jsonAnyObject 更改为 Any:

fileprivate func checkForAuthorizationFailure(_ json: Any) -> Bool {

        let responseMessage = json["response"]! as? String
        if responseMessage == "Unauthorized. Invalid token or email." {
            return true
        }

        return false
    }

但是在行中:let responseMessage = json["response"]!作为? String 我现在收到错误:“Type Any 没有下标成员”。我在这里做错了什么?

最佳答案

在使用下标之前,您必须将 Any 转换为 AnyObject。

fileprivate func checkForAuthorizationFailure(_ json: Any) -> Bool {

    let responseMessage = (json as AnyObject)["response"]! as? String
    if responseMessage == "Unauthorized. Invalid token or email." {
        return true
    }

    return false
}

关于ios - Type Any 没有下标成员 Swift 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39641676/

相关文章:

json - 错误序列化

ios - 如何在 IOS 中查找照片 Assets 的标识符

ios - 带有 xib 的 UITableViewCell

iOS - 执行 block 后从 heightForRowAtIndexPath 返回值

ios - 如何在 iPhone UILabel 中设置字距调整

swift - 如何使用 Swift KeyPaths 的异构数组

ios - 如何在 Xcode 7 和 Swift 2 中创建圆角矩形标签

ios - 平移手势不会将触摸转发到 Mapbox MGLMapView

objective-c - UIActionSheet showInView 上的 iPad NSInternalInconsistencyException

ios - 小时:minutes:seconds in Date Picker swift怎么过