我的 JSON 是:
[
{
"a": "1",
"b": "2"
}
]
let parameters: Parameters = [
<here goes the JSON>
]
Alamofire.request(URL, method: .put, parameters: parameters, encoding: JSONEncoding.default, headers: headers).validate().responseJSON
我知道参数是 [String:AnyObject] 的字典,但我需要像在我的第一个 JSON 中一样传递它
我需要将其作为参数发送,但我认为我只能发送一个 [String: AnyObject],或者至少这就是 Alamofire 迁移指南中示例的工作方式,所以我的问题是如何实现这一点? 我正在使用 Alamofire 4
最佳答案
我使用了一个名为 SwiftyJSON 的库,使用它您可以简单地执行以下操作:
var jsonArray: JSON = [
"array": [1, 2],
"users": [
[
"id": 1,
"info": [
"name": "name1",
"email": "email1"
],
"nums": [123, 124, 125]
],
[
"id": 2,
"info": [
"name": "name2",
"email": "email2"
],
"nums": [12, 13, 14]
]
]]
关于swift - 如何将 json 对象列表作为参数发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43766273/