post Alamofire 中的数组
post array in Alamofire
如何使用 Alamofire post 数组。 Alamofire请求只接受Dictionary类型作为参数:[String : Any]
.
但我想传递一个数组作为参数,而不是字典。
Alamofire.request(url, method: .post, parameters: [String : Any], encoding: JSONEncoding.default, headers: [:])
有什么办法可以解决吗..?
var request = URLRequest(url: try! "your api".asURL())
request.httpMethod = "POST"
let arrParam = ["abc", "xyz"]
request.httpBody = try! JSONSerialization.data(withJSONObject: arrParam)
Alamofire.request(request).responseJSON { response in
switch (response.result) {
case .success:
//success code here
case .failure(let error):
//failure code here
}
}
如何使用 Alamofire post 数组。 Alamofire请求只接受Dictionary类型作为参数:[String : Any]
.
但我想传递一个数组作为参数,而不是字典。
Alamofire.request(url, method: .post, parameters: [String : Any], encoding: JSONEncoding.default, headers: [:])
有什么办法可以解决吗..?
var request = URLRequest(url: try! "your api".asURL())
request.httpMethod = "POST"
let arrParam = ["abc", "xyz"]
request.httpBody = try! JSONSerialization.data(withJSONObject: arrParam)
Alamofire.request(request).responseJSON { response in
switch (response.result) {
case .success:
//success code here
case .failure(let error):
//failure code here
}
}