[英]Alamofire and SwiftyJSON for Swift 2.0
我今天要更新Swift 2.0的代码,但是该行
var json = JSON(json)
给我以下错误
无法使用类型(结果)的参数列表调用类型为“ JSON”的初始化器
你们知道我应该如何更改代码吗?
@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
属性
因此它将是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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.