ios - Swift - 无法使用类型为 'JSON' 的参数列表调用类型为 '(Response<AnyObject, NSError>)' 的初始值设定项

标签 ios json xcode swift

我在使用 Xcode 6.2 升级到 Xcode 7.0.1 后收到此错误消息。

/Users/ZERO/Documents/Xcode/XXXXX/Controllers/LoginViewController.swift:75:35: Cannot invoke initializer for type 'JSON' with an argument list of type '(Response)'

我的代码。

Alamofire.request(.POST , "http://192.168.1.124/wsesb.asmx/WSIniLogin", parameters: ["device_id": UIDevice.currentDevice().identifierForVendor!.UUIDString,"acc_token":acc_token])
            .responseJSON { response in
                if response.result.isSuccess {
                    var jsonObj = JSON(response) //error here
                        if(jsonObj[0]["Status"] == "SUCCESS"){//error here
                            if(jsonObj[0]["Data"][0]["Status"] == "SUCCESS"){ //error here

                            }
                         }
                }
        }

我的播客文件设置:

pod 'Alamofire', '~> 3.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'

最佳答案

responseResponse 类型的 Struct。如果您需要从中获取 JSON,请执行以下操作:

if response.result.isSuccess {
    var jsonObj = JSON(response.result.value)
    ...
}

关于ios - Swift - 无法使用类型为 'JSON' 的参数列表调用类型为 '(Response<AnyObject, NSError>)' 的初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33430917/

相关文章:

ios - 获取 Laravel JSON feed 中帖子的页码

python - 如何对 pandas 系列的元素进行条件分支?

ios - 为什么 UISwitch onImage/offImage 属性在 iOS 7 上不起作用?

iphone - 打击 iOS 应用内购买盗版的策略?

ios - swift/https : NSURLSession/NSURLConnection HTTP load failed

cocoa-touch - [UIImageView _isChargeEnabled] : message sent to deallocated instance

php - Magento - onePage 结账和 SSL (HTTPS)

javascript - 未捕获的语法错误 : Unexpected token : jQuery ajax

swift - 选项单击变量时出现 xcode 错误

swift - 如何使用 XCode 的 Interface Builder 在 Messenger 中创建气泡聊天 TableViewCell?