iOS unicode转中文

swift版本:适合5.2以上

直接上代码:

func convertChina(uStr: String) -> String {
    let tempValue1 = uStr.replacingOccurrences(of: "\\u", with: "\\U");
    let tempValue2 = tempValue1.replacingOccurrences(of: "\"", with: "\\\"");
    let tempValue3 = "\"".appending(tempValue2).appending("\"");
    let tempData = tempValue3.data(using: .utf8)
    let resultString = try? PropertyListSerialization.propertyList(from:
tempData!, options:
PropertyListSerialization.ReadOptions.mutableContainersAndLeaves,
format: nil) as? String
    return resultString ?? uStr
}


版权声明:本文为yaojinhai06原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。