let parameters = [
"alert": model.alert, //Bool
"distance": model.distance, //Int
"minAge": model.minAge, //Int
"maxAge": model.maxAge, //Int
"access_token": access_token //String
]
Alamofire.request(.POST, Constants.Domain + "/accounts/discovery-settings", parameters: parameters).responseJSON{
(req, res, json, error) in
}
我之前做了一个非常类似的请求并且它有效。根据Alamofire的说法,我可以将参数设置为任何东西,对吗?
编辑:
如果我删除这些行,那么编译就好了。 Bool和Int类似乎是问题所在。
"alert": model.alert, //Bool
"distance": model.distance, //Int
"minAge": model.minAge, //Int
"maxAge": model.maxAge, //Int
模型是:
class DiscoverySettings {
var alert: Bool
var distance: Int
var minAge: Int
var maxAge: Int
private init(){
alert = true
distance = 10
minAge = 18
maxAge = 25
}
}
https://github.com/Alamofire/Alamofire#post-request-with-url-encoded-parameters
答案 0 :(得分:0)
由于您没有真正发布错误,因此很难说,但我猜您在字典中遇到了桥接问题。试试以下内容:
let parameters: [String: AnyObject] = [
"alert": model.alert, //Bool
"distance": model.distance, //Int
"minAge": model.minAge, //Int
"maxAge": model.maxAge, //Int
"access_token": access_token //String
]
let request = Alamofire.request(.POST, Constants.Domain + "/accounts/discovery-settings", parameters: parameters)
request.responseJSON { request, response, json, error in
println(request)
println(response)
println(json)
println(error)
}
希望这有助于解决问题。如果它没有,那么请发布您的实际错误,我很乐意修改我的答案。