gpt4 book ai didi

swift - Alamofire 发送对象作为参数

转载 作者:搜寻专家 更新时间:2023-10-31 22:32:51 25 4
gpt4 key购买 nike

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

  {
"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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com