swift unicode 转 utf8 中文

979 阅读1分钟

针对json串

 let jsonStr = "{\"name\":\"\\u5f20\\u4e09\"}"
 let json = try? JSONSerialization.jsonObject(with: jsonStr.data(using: String.Encoding.utf8, allowLossyConversion: true)!, options: JSONSerialization.ReadingOptions.mutableLeaves)
 var name = (json as! NSDictionary).object(forKey: "name")
 print(name)