美文网首页swift知识点(iOS)
ios swift unicode 转中文 json

ios swift unicode 转中文 json

作者: 荔枝lizhi_iOS程序猿 | 来源:发表于2021-12-29 09:48 被阅读0次

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

        本文链接:https://www.haomeiwen.com/subject/wvkvqrtx.html