gpt4 book ai didi

ios - 在Alamofire中调用POST时使用json字段传递参数

转载 作者:行者123 更新时间:2023-11-30 12:30:12 40 4
gpt4 key购买 nike

我在 swift 3 中遇到问题:

我有一个API,我需要访问它以获取应用程序中的数据,但它所需的参数采用以下格式:

"jsonRequest" = {
"header" : "GetLocationListReq",
"accessKey" : "1234567890abcdefghij"
}//this is in json format.

我尝试将此参数作为字典传递来调用API,但此时我收到了此消息错误:

Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed

有人知道我该如何解决这个问题吗?

最佳答案

我认为您想在请求 header 中传递这些内容。

为此你需要这样做

let headers = ["header": "GetLocationListReq",
"accessKey": "1234567890abcdefghij"]
Alamofire.request(url, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: headers).responseJSON{
r in
//do what you want here
}

希望这会起作用。

关于ios - 在Alamofire中调用POST时使用json字段传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43651486/

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