【问题标题】:post array in Alamofire [duplicate]在 Alamofire 中发布数组 [重复]
【发布时间】:2020-05-07 04:48:36
【问题描述】:

如何使用 Alamofire 发布数组。 Alamofire 请求仅接受 Dictionary 类型作为参数:[String : Any]

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

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

有什么办法可以解决..?

【问题讨论】:

  • 你可以在字典中添加数组..?

标签: ios swift alamofire


【解决方案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
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 2017-09-05
    • 2016-09-25
    • 2018-10-06
    • 2018-08-04
    • 1970-01-01
    • 2019-10-11
    • 1970-01-01
    相关资源
    最近更新 更多