'Pass array as parameter key in Swift using Alamofire
I am trying to pass array as key in the parameter but i am getting below error:
The underlying encoder failed with the error: invalidRootObject("array([Alamofire.URLEncodedFormComponent.array([Alamofire.URLEncodedFormComponent.string("link")]), Alamofire.URLEncodedFormComponent.string("24")])")
Here is my code for parameter:
let parameters: [[String]: String] = [
["link"]: linkId
]
Solution 1:[1]
URLEncoding handles by default the Array type as a value of a Dictionary in parameters (not as a key like in your example code) It even adds the brackets in the key by default.
So, something like this should work fine:
let parameters: [String: Any] = [
"links": [84, 11, 83, 24]
]
AF.request(url, method: .put, parameters: parameters, encoding: URLEncoding.default).response { response in
// ...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gcharita |

