菜鸟教程小白 发表于 2022-12-11 20:30:11

ios - 如何在 iOS 中解码\\u00e2\\u0080\\u0099


                                            <p><p>我收到以下字符:</p>

<pre><code>\\u00e2\\u0080\\u0099
</code></pre>

<p>从服务器端,我想将其解码为正确的字符“`”,所以请告诉我如何快速做到这一点。</p>

<p>我不想使用替换字符串方法,因为我想要一个适用于所有 unicode 到字符串转换的通用解决方案。</p>

<p>谢谢,</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您的意思是 <code>"\\u00e2\\u0080\\u0099"</code> 18 个字符的字符串,则必须对其进行转义才能将这些序列转换为它们的实际值。</p>

<p>这是一种可能的方法:</p>

<pre><code>let input = &#34;located in the heart of Wanchai\\u00e2\\u0080\\u0099s Star&#34;
let str = String(data: input.data(using: .utf8)!, encoding: String.Encoding.nonLossyASCII)
</code></pre>

<p>这给出了<code>“位于湾仔之星中心”</code>。</p>

<p>如前所述,<code>"\\u00e2\\u0080\\u0099"</code> 代表一个<code>"â"</code>。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 iOS 中解码\\u00e2\\u0080\\u0099,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/52075402/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/52075402/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 iOS 中解码\\u00e2\\u0080\\u0099