简体   繁体   English

使用Alamofire请求方法在POST的请求正文中发送JSON对象数组

[英]Send an array of JSON objects in the request body of a POST using the Alamofire request method

I have an array of JSON objects that I would like to pass into the request body of a POST request to our server. 我有一个JSON对象数组,我希望将这些对象传递到服务器的POST请求的请求正文中。 However the method signature for the request method only takes a dictionary as its parameters: 但是,request方法的方法签名仅将字典作为其参数:

func request(method: Alamofire.Method, _ URLString: URLStringConvertible, parameters: [String : AnyObject]? = default, encoding: Alamofire.ParameterEncoding = default, headers: [String : String]? = default) -> Alamofire.Request

Is there a way to currently do this in Alamofire without creating the NSURLRequest yourself? 目前有没有办法在Alamofire中执行此操作而无需自己创建NSURLRequest? Or is it in the plan for future development? 还是在未来的发展计划中?

You will need to use the .Custom parameter encoding to do this or manually create the NSURLRequest yourself. 您将需要使用.Custom参数编码来执行此操作,或者自己手动创建NSURLRequest Another possible option would be to modify the server to accept the array with a parameter name in the JSON. 另一个可能的选择是修改服务器以在JSON中接受带有参数名称的数组。

As of right now, there are no plans to support this feature, but thank you for making us aware of this limitation. 截至目前,尚无计划支持此功能,但感谢您使我们意识到这一限制。 I have added the issue to our internal Trello board and we will discuss whether we would like to support this in the future. 我已将该问题添加到我们的内部Trello董事会中,我们将讨论我们是否将来希望支持这一问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM