[英]array of objects set to be parameter when using POST request of Alamofire
I am using Alamofire to POST a request to the server, the body of the request contains one parameter that in the form of : 我正在使用Alamofire向服务器发布请求,请求的主体包含一个参数,形式为:
list: [ { "phone":"13917115283", "name": "Sky" }, { "phone":"13689652145", "name": "RJ" } ]
Any idea how to post such a request? 知道如何发布这样的请求吗? Thanks
谢谢
You can easily achieve this easily by using SwiftyJSON 您可以使用SwiftyJSON轻松实现此目标
Install it via Cocoapods or manually. 通过Cocoapods或手动安装。 For manually you can simply download and add the SwiftyJSON.xcodeproj file in your workspace.
对于手动,您只需在工作区中下载SwiftyJSON.xcodeproj文件并将其添加。
Add SwiftyJSON framework for iOS in Build Phases 在构建阶段为iOS添加SwiftyJSON框架
Now simply import it in your ViewController 现在只需将其导入您的ViewController
import SwiftyJSON
Even after importing if Xcode doesn't recognize it.Clean and build it. 即使在导入后,如果Xcode无法识别它,请清理并构建它。
Code 码
var arrDic: NSArray = [
["phone": "13917115283", "name": "Sky"]
, ["phone": "13689652145", "name": "RJ"]
]
let response = [ "list" : JSON(arrDic) ]
print(JSON(response))
Final Output 最终输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.