gpt4 book ai didi

ios - 如何使用 Alamofire Swift 4 以 JSON 编码传递数据

转载 作者:行者123 更新时间:2023-11-28 10:09:52 26 4
gpt4 key购买 nike

无法弄清楚如何使用 Alamofire .post 方法 将日期传递给服务器。我必须像这样形成 JSON 正文:

{
"title": "My Title",
"locations": [
{
"location": "locationID"
}
],
}

我被困在“位置” 属性上。可能,它必须是一个对象数组,具有一个字符串类型的位置属性。目前我的代码是:

@IBAction func createEvent(_ sender: Any) {
let parameters: Parameters = [
"title": Event.title ?? nil,
"locations": //What have I wright here?
]

Alamofire.request(requestURL,
method: .post,
parameters: parameters,
encoding: JSONEncoding.default,
headers: headers).responseJSON {response in

switch response.result {
case .success:
print(response)

}
case .failure(let error):

print(error)
}
}
}

请帮忙。

最佳答案

你可以试试

let parameters: Parameters = [
"title": Event.title ?? nil,
"locations": [["location":"idherrr"]]
]

关于ios - 如何使用 Alamofire Swift 4 以 JSON 编码传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49382831/

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