swift 字典转json字符串

func toJSONString(dict:NSDictionary?)->String{

let data = try? NSJSONSerialization.dataWithJSONObject(dict!, options: NSJSONWritingOptions.PrettyPrinted)

let strJson = NSString(data: data!, encoding: NSUTF8StringEncoding)

return strJson! as String

}

你可能感兴趣的:(swift 字典转json字符串)