我需要将对象列表发送到端点。 所需类型具有以下键
{
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/