ccl*_*oyd 42 dictionary nsdictionary nsmutabledictionary swift
现在我知道,当swift编译它只是创建一个NSDictionary,但NSDictionary和Swift词典有不同的语法.有没有办法(通过循环或其他东西)将NSDictionary转换为相同类型的快速字典<key, value>
?
要么
有没有办法将其转换为Swift字典而不是NSDictionary?
let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary
Run Code Online (Sandbox Code Playgroud)
Arn*_*rno 27
使用:
let jsonDic = NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers, error: &error) as Dictionary<String, AnyObject>;
Run Code Online (Sandbox Code Playgroud)
NSDictionary
并且Dictionary
几乎可以互换。所以没有必要,但是你可以:
let jsonDict = (NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary) as Dictionary
Run Code Online (Sandbox Code Playgroud)