Alamofire' JSON写的无效类型'升级后出错

时间:2016-09-27 15:53:43

标签: ios json swift alamofire

以下代码与Alamofire 3.0合作:

let headers = [
    "content-type": "application/json",
    "cache-control": "no-cache",
    ]
let parameters = [
    "access_token": token.tokenString,
    "client_id": bundleID,
]

Alamofire.request(.POST, url, headers: headers, parameters: parameters, encoding: .JSON).responseJSON { response in
    // ...
}

我在更新到Alamofire 4.0 / Swift3 / XCode 8之后更改了请求:

Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
    // ...
}

我收到错误

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)'

我一直在寻找这个问题的解决方案,但无法找到相关内容。

1 个答案:

答案 0 :(得分:2)

您的参数肯定有问题。确保token.tokenStringbundleID都是String

相关问题