如何使用Alamofire将单个对象作为参数发送

时间:2018-11-30 20:28:59

标签: ios json swift parameters alamofire

我遇到了一个我没有想到会发生的问题。 我需要对仅允许使用此功能的第三方API发出发布请求

let parameters: Parameters = [{
        "id": "1",
        "original-address": "Some city, Some street"}]

您可以看到它不是字典,因此编译器会说Cannot convert value of type '[() -> String]' to specified type 'Parameters' (aka 'Dictionary<String, Any>')

我无法删除括号,因为我的第三方API不会响应该请求。

如何通过Alamofire发送此类请求?

我尝试了来自我们心爱的Stackoverflow的一些建议,但还是没有运气。

1 个答案:

答案 0 :(得分:0)

[ { _id: '5ba39a12179b771820413ad8', branches: [ { _id: '3nc26645121f0613be08167r', name: 'New York' }, { _id: '3fc26645121f0613be08185d', name: 'Los Angeles' }, { _id: '2hc26648121f0613be081862', name: 'Seattle' }, { _id: '7jc2664a121f0613be081869', name: 'Chicago' }, { _id: '7ju2664a121f0613be08186e', name: 'Charlotte' } ], updatedAt: '2018-09-20T13:01:06.709Z', createdAt: '2018-09-20T13:01:06.709Z' }, { _id: '3ya39a12179b771820413af5', branches: [ { _id: '3nc26645121f0613be08167r', name: 'New York' }, { _id: '5ac26645121f0613be08145d', name: 'Miami' }, { _id: '5ac2664a121f0613be08154s', name: 'Sacramento' } ], updatedAt: '2018-09-20T13:01:06.709Z', createdAt: '2018-09-20T13:01:06.709Z' } ]; Parameters的{​​{1}},您分配

typealias

看起来像是字典的json数组(甚至不是Dics的快速数组),因此您无法将其传递到[String:Any]来完成需要将其作为[{ "id": "1", "original-address": "Some city, Some street"}] 发送到请求正文中的操作看Sending json array via Alamofire

相关问题