如何在 Swift 3 中使用 Alamofire 在 POST 请求中将给定的 JSON 作为参数发送?
Posted
技术标签:
【中文标题】如何在 Swift 3 中使用 Alamofire 在 POST 请求中将给定的 JSON 作为参数发送?【英文标题】:How to send the given JSON as parameters in the POST request using Alamofire in Swift 3? 【发布时间】:2017-02-24 11:33:43 【问题描述】:我有如下 JSON,它必须作为 POST 请求的正文包含,
"type" : "myData",
"condition" : "projectid": 40
我的 POST 请求应该如何使用 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 欢迎朋友 :)以上是关于如何在 Swift 3 中使用 Alamofire 在 POST 请求中将给定的 JSON 作为参数发送?的主要内容,如果未能解决你的问题,请参考以下文章