【问题标题】:How can i send a JSON variable as param in alamofire post request如何在 alamofire 发布请求中发送 JSON 变量作为参数
【发布时间】:2018-07-24 11:59:34
【问题描述】:
Alamofire.request("https://test.com", method: .post, parameters: d, encoding: JSONEncoding.default)
        .responseJSON { response in
        print(response)
    }

我正在使用上述方法使用 Alamofire 发送 post 请求。这里的“d”是 JSON 变量。但是一个错误是在调用中说额外的争论方法。为什么会这样。

【问题讨论】:

  • 添加您作为参数发送的 json。
  • "d" 不能是 JSON 变量!!!必须是 [String: Any] 类型的变量。检查我的答案。

标签: ios json swift alamofire xcode8


【解决方案1】:

尝试像这样发送参数:

let params: [String: Any] = [Key 1: value1, Key 2: value2]

【讨论】:

    【解决方案2】:

    这是正确的格式。

    您的情况中的参数 d 必须是类型:[String: Any]

    let d: [Sting: Any] = [
                "some key": some value,
                "some key": some value,
                ]
    
            Alamofire.request("url", method: .post, parameters: d)
                .validate()
                .responseJSON {
                    (response) in
            }
    

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      • 2017-05-15
      • 2020-04-25
      相关资源
      最近更新 更多