array of objects set to be parameter when using POST request of Alamofire

拟墨画扇 提交于 2019-12-12 02:27:46

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/33061565/array-of-objects-set-to-be-parameter-when-using-post-request-of-alamofire

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!