适用于Swift 2.0的Alamofire和SwiftyJSON [英] Alamofire and SwiftyJSON for Swift 2.0

查看:82
本文介绍了适用于Swift 2.0的Alamofire和SwiftyJSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天要更新Swift 2.0的代码,但是该行

I am updating my code for Swift 2.0 for today, however the line

var json = JSON(json)给我以下错误


无法为类型为
的参数列表调用类型为 JSON的初始化器(结果)

Cannot invoke intializer for type 'JSON' with an argument list of type (Result)

你们知道我应该如何更改代码吗?

Do you guys have any idea how should I change my code?

@IBAction func changePassword(sender: UIBarButtonItem) {
    Alamofire.request(.POST, AppDelegate.kbaseUrl + "users/me/password", parameters: ["old_password": self.oldPasswordTextField.text!, "new_password": self.newPasswordTextField.text!, "confirm_password": self.confirmPasswordTextField.text!], encoding: .JSON)
        .responseJSON {
            (req, res, json) in
            var json = JSON(json)
            if json["meta"]["status"]["code"] == 200 {
                self.navigationController?.popViewControllerAnimated(true)
            }
            let alert = UIAlertView(title: json["meta"]["msg"]["subj"].stringValue, message: json["meta"]["msg"]["body"].stringValue, delegate: nil, cancelButtonTitle: "Close")
            alert.show()
    }
}


推荐答案

现在响应对象附带了它,因此您必须使用响应对象的 value 属性

Now the response object came with it so you have to use the value property from the response object

因此它将是 JSON(json.value!)

例如:

Alamofire.request(.GET, "http://api.androidhive.info/contacts/", parameters: nil, encoding: .JSON, headers: nil).responseJSON { (req, res, json) -> Void in
    print("\(res?.allHeaderFields)")
    print("JSON - \(json.value)")

    let swiftJsonVar = JSON(json.value!)
    print(swiftJsonVar)
}

这篇关于适用于Swift 2.0的Alamofire和SwiftyJSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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