Alamofire 火变量类型没有下标成员 [英] Alamofire fire variable type has no subscript members

查看:24
本文介绍了Alamofire 火变量类型没有下标成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新到 Alamofire 4 并将我的代码更新到 Swift 3 后,由于某种原因,我的所有请求都不起作用.我尝试使用的变量以红色突出显示,并说任何类型的变量都没有下标成员"

After updating to Alamofire 4 and updating my code to Swift 3, all of my requests are not working for some reason. The variables that I am trying to utilize are highlighted in red and say "Type Any' has no subscript members"

这是我的代码:

    Alamofire.request("https://example.com/notifications.php?action=(action)&UUID=(UniversalUUID)&token=(token)").responseJSON{ (response) -> Void in

      if let JSON = response.result.value{
     let message = JSON["message"] as! String

    print(message)

}

推荐答案

您需要将 添加为?[字符串:任意]

Alamofire.request(yourURL).responseJSON { (response) in
        switch response.result {
        case .success:
            if let JSON = response.result.value as? [String: Any] {
                let message = JSON["message"] as! String
                print(message)
            }
        case .failure(let error):
            // error handling
        }
    }

这篇关于Alamofire 火变量类型没有下标成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆