Alamofire 4, Swift 3 and building a json body

霸气de小男生 提交于 2019-12-05 08:18:34

You need to pass parameter as [String:Any] dictionary, so create one dictionary as your passing JSON like this.

let params = [ 
                "title":"exampleTitle",
                "hashTags": [["name":"tag1"],["name":"tag2"]],
                "uploadFiles":[["fileBytes":"seriesOfBytes\n","filename":"upload.txt"]]
             ]

Now pass this params as parameter in Alamofire request.

Alamofire.request(postURL, method: .post, parameters: params, encoding: JSONEncoding.default)
    .responseJSON { response in
        debugPrint(response)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!