在SWIFT中将字典转换为JSON我已经创建了下一个字典:var postJSON = [ids[0]:answersArray[0], ids[1]:answersArray[1], ids[2]:answersArray[2]] as Dictionary我得到了:[2: B, 1: A, 3: C]那么,如何将其转换为JSON呢?
2 回答
杨魅力
TA贡献1811条经验 获得超6个赞
let dict = ["0": "ArrayObjectOne", "1": "ArrayObjecttwo", "2": "ArrayObjectThree"]var error : NSError?let jsonData = try! NSJSONSerialization.dataWithJSONObject(dict, options: NSJSONWritingOptions.PrettyPrinted)let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding)! as Stringprint(jsonString)
{ "0" : "ArrayObjectOne", "1" : "ArrayObjecttwo", "2" : "ArrayObjectThree"}
添加回答
举报
0/150
提交
取消