ios swift unicode 转中文 json

//
// 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

}
}

你可能感兴趣的:(ios swift unicode 转中文 json)