swift - 在 alamofire 中发送对象数组

标签 swift alamofire

我需要将对象列表发送到端点。 所需类型具有以下键

{
  id: Int;
  all: Bool;
  batch: Bool;
  chapter: Bool;
  myNetwork: Bool;
  categoryId: Int;
}

api 需要上述对象的列表。我像这样使用 Alamofire 的参数类型生成了一个列表。

[
    ["chapter": "true", "myNetwork": "false", "id": "3", "categoryId": "1", "memberId": "13", "batch": "true", "all": "true"], 
    ["categoryId": "2", "batch": "false", "myNetwork": "true", "all": "true", "id": "891", "memberId": "13", "chapter": "true"], 
    ["batch": "false", "memberId": "13", "categoryId": "3", "all": "false", "id": "1779", "myNetwork": "false", "chapter": "false"], 
    ["batch": "true", "id": "2667", "all": "false", "chapter": "true", "memberId": "13", "categoryId": "4", "myNetwork": "false"]
]

但是显示错误

Cannot convert value of type '[[String : Any]]' to expected argument type 'Parameters?' (aka 'Optional>')

我如何使用 Alamofire 将这个对象列表发送到 API?发送请求的代码

Alamofire.request("(APIManager.url)/Privacy/Update", method: .post, parameters: params, encoding: JSONEncoding.default, headers: APIManager.headers)

最佳答案

你的参数应该是这样的

["key": "value", "key": "value"]

这是一个字典,你使用的是一个字典数组,这就是你得到错误的原因

关于swift - 在 alamofire 中发送对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56291826/

相关文章:

ios - 如何使用 IBAction 从一个 Storyboard移动到另一个 Storyboard?

swift - 在 tvOS 中删除 "Adjust image when focused"的视觉外观

ios - 添加一个 "Done"按钮以关闭以编程方式创建的 UIViewController

swift - 从 Alamofire.request() 返回数据

ios - 如何更改 AVPlayer 中播放音频的速度?

swift - fatal error : use of unimplemented initializer 'init()' for class

ios - 在 Alamofire POST 方法中发布多个 json 对象 - Swift/IOS

ios - 在 Swift 中将视频转换为二进制数据

ios - 如何使用 NSMutableURLRequest 或 Alamofire

swift - alamofire 获取请求返回空值