【发布时间】:2017-06-27 23:58:33
【问题描述】:
我将为 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)
【问题讨论】:
-
检查这个答案也许可以帮助你stackoverflow.com/questions/44484772/…
-
将
as! Dictionary<String, String>更改为as [String: Any]。