swift - 如何将 json 对象列表作为参数发送?

标签 swift alamofire

我的 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/

相关文章:

ios - Swift 函数 - 传递可选对象

ios - UIButton Touch Down 没有在 Swift 中注册

swift - 如何使用 Alamofire 在 Swift 中编写 curl 命令?

swift - 发布请求不添加对象的内部数组

arrays - Swift 选择器数组错误

iOS:在 pod 中使用 Segment-Firebase 时构建 Xcode 项目时出错

ios - 如何在编辑时更改 UITextField

ios - 收到 MailChimp 错误 "Your request did not include an API key.",即使使用 Alamofire 包含 API key

ios - Swift 函数异步

ios - 解析 JSON 数组的问题