Alamofire中的帖子数组

问题描述 投票:-2回答:1

如何使用Alamofire发布阵列。 Alamofire请求仅将字典类型作为参数:[String : Any]

但是我想将数组作为参数传递,而不是字典。

Alamofire.request(url, method: .post, parameters: [String : Any], encoding: JSONEncoding.default, headers: [:])

有什么办法解决它..?

swift alamofire
1个回答
-1
投票
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
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.