适用于Swift 2.0的Alamofire和SwiftyJSON

编程入门 行业动态 更新时间:2024-10-27 06:24:49
本文介绍了适用于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, "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

本文发布于:2023-11-26 06:08:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   Swift   Alamofire   SwiftyJSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!