gpt4 book ai didi

ios - 使用 URLEncoding 为 Alamofire 帖子编码 Swift 数组

转载 作者:搜寻专家 更新时间:2023-10-31 22:05:08 27 4
gpt4 key购买 nike

重新发布,因为我搞砸了之前的编码类型......我需要使用 URLEncoding 将数组发送到带有 Alamofire 的服务器。但是,它需要以某种方式编码,以便 Alamofire 正确发送。这是我的代码:

let parameters: [String : Any] = [
"names" : ["bob", "fred"]
]

Alamofire.request(urlString, method: .post, parameters: parameters, encoding: URLEncoding.default)
.responseJSON { response in
// etc
}

然而,参数永远不会被编码,只是作为 nil 发送。我如何对其进行编码?

最佳答案

截至目前,您可以针对此问题使用参数:

let enc = URLEncoding(arrayEncoding: .noBrackets)
Alamofire.request(url, method: .get, parameters: parameters, encoding: enc)

关于ios - 使用 URLEncoding 为 Alamofire 帖子编码 Swift 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44989617/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com