以下代码与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)'
我一直在寻找这个问题的解决方案,但无法找到相关内容。
答案 0 :(得分:2)
您的参数肯定有问题。确保token.tokenString
和bundleID
都是String
。