Alamofire 5 POST 方法使用数组参数 swift 5

Alamofire 5 POST method having array parameters usage with swift 5

我正在使用 Swift 5 和 Almofire 5.0.2 开发一个 iOS 项目。我尝试了与此类似的在线线程上建议的所有选项,但看起来我仍然遗漏了一些东西。

我在 POST 方法 API 调用过程中遇到困难,其中包含一组项目作为请求正文的一部分。

API 看起来像:

@RequestMapping(...)
SomeResponse doSomething (@RequestBody SomeRequest request) {}

我正在使用 Swift 5 和 alamo fire 5.0.2 版本,我尝试了上面的选项和下面的选项,但它根本没有命中 API(returns AFError ):

let parameters: [String: Any] = [
            "block": true,
            "items": [],
            "name": "xxxxx",
            "mobile": "xxxxxxxxxx",
            "email": "xxxx@gmail.com",
            "List": [["place": "london"],["place": "holand"]]

  ]

AF.request(BookingConstants.httpEndpoint, method: .post, parameters: parameters, headers: headers)
            .validate()
            .responseData { response in

}

我在 java spring 引导 API 端收到此错误:

Invalid index in property path 'item[][place]'; nested exception is java.lang.NumberFormatException: For input string: ""] with root cause

java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_221]
    at java.lang.Integer.parseInt(Integer.java:592) ~[?:1.8.0_221]
    at java.lang.Integer.parseInt(Integer.java:615) ~[?:1.8.0_221]
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:663) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyHoldingValue(AbstractNestablePropertyAccessor.java:402) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.processKeyedProperty(AbstractNestablePropertyAccessor.java:298) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:289) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:859) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.validation.DataBinder.doBind(DataBinder.java:755) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:192) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:106) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE

我知道我遗漏了一些东西但无法弄清楚。有人可以帮我解决这个问题吗?请让我知道您的 comments/suggestions(如果有)。提前致谢

我切换回Alamofire 4.0.1版本,使用Alamofire上传方式实现

let objectAsJSON: JSON = request.toJSON()
let data: Data = try objectAsJSON.serialize()

Alamofire.upload(data, to: BookingConstants.httpEndpoint, headers: headers)
                .validate()
                .responseData { response in
        // response code logic

}