swift 开发 - NSDictionary与NSData互转
2019-06-18 本文已影响0人
谌文
1、NSDictionary转NSData
let data: NSData = NSKeyedArchiver.archivedData(withRootObject:dataDic) as? NSData ?? NSData()
2、NSData转NSDictionary
let dic = NSKeyedUnarchiver.unarchiveObject(with: data as? Data)as!NSDictionary
3、NSDictionary转Data
let date = try? JSONSerialization.data(withJSONObject: dic, options: .prettyPrinted)
4、Data转Dictionary
let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers)as! Dictionary<String,String>