gpt4 book ai didi

json - 在 swift 中用字符串列表构造一个 JSON 负载

转载 作者:行者123 更新时间:2023-11-28 15:30:13 24 4
gpt4 key购买 nike

我会为 POST 服务调用动态构建以下有效负载。我不确定如何在字典中创建字符串列表

{
"Id":"2025",
"deviceType": "iphone",
"category": ["Dental", "Vision"]
}

我的代码

var categoryList = ["Dental", "Vision"]
let json = ["Id": "2025", "deviceType": "iphone", "category": categoryList] as! Dictionary<String, String>
let jsonData = try? JSONSerialization.data(withJSONObject: json)

最佳答案

你可以这样做:-

无需将json转成数据,直接将json作为参数传到SERVICE CAll即可

let jsonToSend:[String:Any] = [
"Id":"pass your id here",
"deviceType":"device type here",
"category":"category array here"
]

关于json - 在 swift 中用字符串列表构造一个 JSON 负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44791719/

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