使用Alamofire的POST请求时设置为参数的对象数组 [英] array of objects set to be parameter when using POST request of Alamofire

查看:357
本文介绍了使用Alamofire的POST请求时设置为参数的对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Alamofire向服务器发布请求,请求的主体包含一个参数,形式为:



 列表:[{ phone: 13917115283, name: Sky},{ phone: 13689652145, name: RJ}]  



有人知道如何发布这样的请求吗?谢谢

解决方案

您可以使用



现在只需将其导入到ViewController中

 导入SwiftyJSON 

甚至在之后如果Xcode无法识别,请导入。清理并构建它。



代码

  var arrDic:NSArray = [
[ phone: 13917115283, name: Sky]
,[ phone: 13689652145 , name: RJ]
]
let response = [ list:JSON(arrDic)]

print(JSON(response))

最终产出




I am using Alamofire to POST a request to the server, the body of the request contains one parameter that in the form of :

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

Install it via Cocoapods or manually. For manually you can simply download and add the SwiftyJSON.xcodeproj file in your workspace.

Add SwiftyJSON framework for iOS in Build Phases

Now simply import it in your ViewController

 import SwiftyJSON

Even after importing if Xcode doesn't recognize it.Clean and build it.

Code

var arrDic: NSArray = [
      ["phone": "13917115283", "name": "Sky"]
    , ["phone": "13689652145", "name": "RJ"]
                        ]
let response = [ "list" : JSON(arrDic) ]

print(JSON(response))

Final Output

这篇关于使用Alamofire的POST请求时设置为参数的对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆