<small id='OhQnN'></small><noframes id='OhQnN'>

        • <bdo id='OhQnN'></bdo><ul id='OhQnN'></ul>
        <legend id='OhQnN'><style id='OhQnN'><dir id='OhQnN'><q id='OhQnN'></q></dir></style></legend>
        <i id='OhQnN'><tr id='OhQnN'><dt id='OhQnN'><q id='OhQnN'><span id='OhQnN'><b id='OhQnN'><form id='OhQnN'><ins id='OhQnN'></ins><ul id='OhQnN'></ul><sub id='OhQnN'></sub></form><legend id='OhQnN'></legend><bdo id='OhQnN'><pre id='OhQnN'><center id='OhQnN'></center></pre></bdo></b><th id='OhQnN'></th></span></q></dt></tr></i><div id='OhQnN'><tfoot id='OhQnN'></tfoot><dl id='OhQnN'><fieldset id='OhQnN'></fieldset></dl></div>
        <tfoot id='OhQnN'></tfoot>
      1. 如何在 Swift 中将 base64String 转换为 String?

        时间:2024-04-14
          <legend id='8E9ER'><style id='8E9ER'><dir id='8E9ER'><q id='8E9ER'></q></dir></style></legend>
            <tbody id='8E9ER'></tbody>
          <tfoot id='8E9ER'></tfoot>

          <small id='8E9ER'></small><noframes id='8E9ER'>

          • <bdo id='8E9ER'></bdo><ul id='8E9ER'></ul>

                1. <i id='8E9ER'><tr id='8E9ER'><dt id='8E9ER'><q id='8E9ER'><span id='8E9ER'><b id='8E9ER'><form id='8E9ER'><ins id='8E9ER'></ins><ul id='8E9ER'></ul><sub id='8E9ER'></sub></form><legend id='8E9ER'></legend><bdo id='8E9ER'><pre id='8E9ER'><center id='8E9ER'></center></pre></bdo></b><th id='8E9ER'></th></span></q></dt></tr></i><div id='8E9ER'><tfoot id='8E9ER'></tfoot><dl id='8E9ER'><fieldset id='8E9ER'></fieldset></dl></div>

                2. 本文介绍了如何在 Swift 中将 base64String 转换为 String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 NSData 中收到来自 web 服务响应的 base64String,如何快速将该 base64String 转换为 String?

                  I am receiving a base64String from webservice response in NSData, how to convert that base64String to String in swift?

                      //Code
                      var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as! NSDictionary  // Response JSON from webservice
                      var base64String : String = ""
                      base64String = jsonResult["Base64String"] as! String  // Retrieve base64String as string from json response
                      println("Base64String Alone: (base64String)")
                  
                  // Code to decode that base64String
                  let decodedData = NSData(base64EncodedString: base64String, options: NSDataBase64DecodingOptions(rawValue: 0))
                                                      println("Decoded:  (decodedData)")
                                                      let decodedString = NSString(data: decodedData!, encoding: NSUTF8StringEncoding)
                                                      println(decodedString) // Prints nil
                  

                  base64String 的编码和解码适用于仅包含文本的文件,如果文件包含某些表格格式/图像,则编码和解码都会给出无效的 base64String.无论文件的内容如何,如何将文件转换为 base64String 编码和解码?文件格式有doc、docx、pdf、txt

                  Encode and decode of base64String works well for the files containing only text, if a file contains some table formats/images both encoding and decoding gives an invalid base64String. How to convert a file into base64String encode and decode whatever the contents of file ? File formats are doc, docx, pdf, txt

                  提前感谢您的帮助!

                  推荐答案

                  试试这个

                  let base64Encoded = "YW55IGNhcm5hbCBwbGVhc3VyZS4="
                  
                  let decodedData = Data(base64Encoded: base64Encoded)!
                  let decodedString = String(data: decodedData, encoding: .utf8)!
                  
                  print(decodedString)
                  
                  println(decodedString)
                  

                  确保您的 base 64 编码字符串有效

                  make sure your base 64 encoded string is valid

                  这篇关于如何在 Swift 中将 base64String 转换为 String?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Swift 中将字符串编码为 Base64? 下一篇:将 base64URL 解码为 base64 -- Swift

                  相关文章

                    <tfoot id='zrY3d'></tfoot>
                  1. <small id='zrY3d'></small><noframes id='zrY3d'>

                      • <bdo id='zrY3d'></bdo><ul id='zrY3d'></ul>

                      <legend id='zrY3d'><style id='zrY3d'><dir id='zrY3d'><q id='zrY3d'></q></dir></style></legend>
                    1. <i id='zrY3d'><tr id='zrY3d'><dt id='zrY3d'><q id='zrY3d'><span id='zrY3d'><b id='zrY3d'><form id='zrY3d'><ins id='zrY3d'></ins><ul id='zrY3d'></ul><sub id='zrY3d'></sub></form><legend id='zrY3d'></legend><bdo id='zrY3d'><pre id='zrY3d'><center id='zrY3d'></center></pre></bdo></b><th id='zrY3d'></th></span></q></dt></tr></i><div id='zrY3d'><tfoot id='zrY3d'></tfoot><dl id='zrY3d'><fieldset id='zrY3d'></fieldset></dl></div>