Alamofire参数 - NSDictionary不能转换为[String:AnyObject]

时间:2015-08-11 20:12:05

标签: ios json swift alamofire

所以我试图用Alamofire发送一个json对象作为参数。我想我已经在他们的文档中遵循了示例,但是我通过方法调用得到了这个错误。

Code with Error

@IBAction func saveButton(sender: AnyObject) {
    var url = "http://b857aaa4.ngrok.io/recruit"

    let parameters = [
        "_id" : firstNameTextField.text,
        "alt_email" : "",
        "forename" : firstNameTextField.text,
        "phone" : recruteePhone.text,
        "recruiter" : [
            "comments" : "",//TODO comments
            "date_met" : "",//TODO tdoays date
            "email" : "",//TODO recruiter email
            "event_name" : ""//TODO event name
        ],
        "surname" : lastNameTextField.text
    ]


    Alamofire.request(.PUT, url, parameters: parameters, encoding: .JSON)
        .responseJSON { (req, res, json, error) in
            if(error != nil) {
                NSLog("Error: \(error)\n")
            } else {
                var json = JSON(json!);
                println("success");
            }
    }

1 个答案:

答案 0 :(得分:12)

将参数声明为

    let parameters: [String: AnyObject] = [

它编译好了。