【问题标题】:How to send single object as a parameter with Alamofire如何使用 Alamofire 将单个对象作为参数发送
【发布时间】:2018-11-30 20:28:59
【问题描述】:

我遇到了一个我没想到会发生的问题。 我需要对只允许这样做的第三方 API 发出 post 请求

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>')

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

如何使用 Alamofire 发送这样的请求?

我已经尝试了我们心爱的 * 的一些建议,但仍然没有成功。

【问题讨论】:

  • Alamofire is arguing 你这是什么意思?你试过去掉括号吗?
  • @EmilioPelaez 我的意思是编译器抛出错误,描述为Cannot convert value of type '[() -> String]' to specified type 'Parameters' (aka 'Dictionary<String, Any>') 我无法删除括号,因为我的第 3 方 API 不会响应此请求。

标签: ios json swift parameters alamofire


【解决方案1】:

Parameterstypealias[String:Any] 并且您分配

[{
    "id": "1",
    "original-address": "Some city, Some street"}]

它看起来像字典的 json 数组(甚至不是 Dics 的 swift 数组),因此您不能将其传递给 Alamofire ,以完成您需要在请求正文中将其发送为 Data 的内容,请查看 @987654321 @

【讨论】:

    最近更新 更多