[英]how to print Chinese not unicode when print NSDictionary in swift
当我打印包含中文的NSDictionary时,Xcode控制台打印unicode,如何将unicode转换为中文?
try this solution 试试这个解决方案
extension Dictionary {
var json: String {
let errorJson = "JSON Format error "
do {
let jsonData = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted)
return String(bytes: jsonData, encoding: String.Encoding.utf8) ?? errorJson
} catch {
return errorJson
}
}
}
using code 使用代码
let dictionary = ["name":"ahmad","age":"22","gender":"male"]
print(dictionary.json)
result on log : 记录结果:
{
"name":"ahmad",
"age":"22",
"gender":"male"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.