swift - Alamofire 发送对象作为参数

标签 swift swift2 alamofire

我很难做一些简单的事情。我要发送的数据如下:

  {
    "nickname":"Rado",
    "social": {
      "data: { 
        "accesstoken":"xx",
        "applicationId":"xx",
        "userId":"xx"
      },
      "type":"whatever"
    }
  }

目前我正在这样做:

           let params = [
                "nickname": userName,
                "social": [
                    "type": "whatever",
                    "data": [
                        "userId": accessToken.userID,
                        "accesstoken": accessToken.tokenString,
                        "applicationId": accessToken.appID
                    ]
                ]
            ]

 Alamofire.request(.POST, "url/users", parameters: params, headers: nil)
                .responseJSON { response in

作为回应,我得到了这个:

{
 "nickname":"Rado",
 "social[data][userId]":"xx",
 "social[data][applicationId]":"xx",
 "social[data][accesstoken]":"xx",
 "social[type]":"something"
}

任何建议将不胜感激!

最佳答案

事实证明,解决方案非常简单。我缺少 encoding: .JSON

    Alamofire.request(.POST, "url/users", parameters: params, headers: nil, encoding: .JSON)
        .responseJSON { response in

    }

关于swift - Alamofire 发送对象作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36175635/

相关文章:

Swift Segmented Control 默认状态

swift - 具有字典或数组类型的 Alamofire 和 responseJSONDecodable

Swift:阻止所有代码,直到函数完成执行

ios - 当我点击不同的标签栏项目时,Lottie 动画停止了

ios - 分段控制/文本字段/DidChange

ios - Alamofire 接受和内容类型 JSON

swift - Alamofire 忽略 timeoutIntervalForRequest 和 timeoutIntervalForResource 参数

xcode - 如何在调试器中查看值?

Swift通用数据转换函数

ios - 当我进入场景时如何设置场景的缩放模式?