【问题标题】:How to send the given JSON as parameters in the POST request using Alamofire in Swift 3?如何在 Swift 3 中使用 Alamofire 在 POST 请求中将给定的 JSON 作为参数发送?
【发布时间】:2017-02-24 11:33:43
【问题描述】:

我有如下 JSON,它必须作为 POST 请求的正文包含,

    {
      "type" : "myData",
      "condition" : {"projectid": 40}
    }

我的 POST 请求应该如何使用 Alamofire 形成?

【问题讨论】:

    标签: json swift swift3 alamofire


    【解决方案1】:

    您只需创建参数Dictionary

    let parameters: [String:Any] = [ "type" : "myData", "condition" : ["projectid" : 40]]
    

    现在用Alamofire 传递这个parameters 字典。

    Alamofire.request(urlString, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in
        print(response)
    }
    

    【讨论】:

    • 像魅力一样工作!
    • @SeaWarrior404 欢迎朋友 :)
    猜你喜欢
    • 2016-08-02
    • 2016-11-19
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多