简体   繁体   中英

Alamofire Parameters - NSDictionary is not convertible to [String : AnyObject]

So I am trying to send a json object as parameters with Alamofire. I think I have followed example in their documentation but I get this error with the method call.

代码有错误

@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");
            }
    }

Declare parameters as

    let parameters: [String: AnyObject] = [

and it compiles okay.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM