ios swift unicode 转中文 json
2021-12-29 本文已影响0人
荔枝lizhi_iOS程序猿
//
// ObjectUnicode.swift
// SwiftApp
//
// Created by Geniune on 2020/1/14.
// Copyright © 2020 Apple. All rights reserved.
//
import UIKit
extension Array {
var unicodeDescription: String {
return self.description.stringByReplaceUnicode
}
}
extension Dictionary {
var unicodeDescription: String {
return self.description.stringByReplaceUnicode
}
}
extension String {
var unicodeDescription: String {
return self.stringByReplaceUnicode
}
var stringByReplaceUnicode: String {
let jsonDict = try? JSONSerialization.jsonObject(
with: self.data(using: String.Encoding.utf8, allowLossyConversion: true)!,
options: JSONSerialization.ReadingOptions.mutableLeaves)
let jsonData = try? JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)
let string_r = String(data: jsonData!, encoding: String.Encoding.utf8)
return string_r ?? self
}
}