2015-10-01 38 views
2

我更新我的代碼爲雨燕2.0的今天,但行Alamofire和SwiftyJSON爲雨燕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() 
    } 
} 

回答

4

現在對象來與它的響應,因此您必須從響應對象

所以使用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) 
} 
+0

謝謝太多了!我花了整個上午在這 – Happiehappie

+0

@Happiehappie歡迎任何時間。 –

+1

@AshishKakkad謝謝,它工作! – iRiziya