我会为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)
答案 0 :(得分:1)
你可以这样做: -
并且无需将json转换为数据,您可以直接在SERVICE CAll中将此json发布为参数
let jsonToSend:[String:Any] = [
"Id":"pass your id here",
"deviceType":"device type here",
"category":"category array here"
]