ios - 中文字符编码问题ios
<p><p>我有一个应用程序支持四种语言。在那个时候,当我用中文用户名登录时,它会显示我这样的响应.. </p>
<blockquote>
<p>[{"0":"41","intid":"41","1":"\u8a00\u3046",<strong>"varfirstname":"\u8a00\u3046"</strong>,"2":"\u8a00\u3046","varlastname":"\u8a00\u3046","3":"\u5730","varusername":"\u5730","4":"[email protected]","varemailid":"[email protected]","5":"qwert","varpassword":"qwert","6":"12345","varmobileno":"12345","7":"Enable","mobileMessage":"Enable","8":"","varphoneno":"","9":"Enable","enumstatus":"Enable","10":"2013-01-30","date_insert":"2013-01-30","11":"2013-01-30","date_edit":"2013-01-30","12":"1.38.28.36","varipaddress":"1.38.28.36"}]</p>
</blockquote>
<p>我想向 UITextfield Text 显示 <strong>"varfirstname"</strong> 。但是当我在 NSLog 中打印它时,我没有得到任何文本。 </p>
<blockquote>
<p><code>NSLog(@"Text is === %@",textfname,text);</code></p>
</blockquote>
<p>如何解码此文本?并在 UITextfield 或 UILabel 上显示。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我刚刚搜索了一下,发现了来自 <a href="https://stackoverflow.com/questions/10838702/how-to-encode-or-decode-url-in-objective-c" rel="noreferrer noopener nofollow">here</a> 的有用答案之一.</p>
<p>中文和日文字符自然不适用于 ASCII 字符串编码。如果您尝试通过 Apple 的方法转义字符串,您绝对应该避免代码重复,将结果存储为 Unicode 字符串。使用以下编码之一:</p>
<pre><code>NSUTF8StringEncoding
NSUTF16StringEncoding
NSShiftJISStringEncoding (not Unicode, Japanese-specific)
</code></pre>
<p><strong>更新</strong></p>
<p>例如,您可以像下面这样编码解码您的中文字符串:</p>
<pre><code>NSString * test = @"汉字马拉松是";
NSString* encodedString =;
NSLog(@"====%@",encodedString);
</code></pre>
<p><strong>输出是:</strong></p>
<blockquote>
<p>%E6%B1%89%E5%AD%97%E9%A9%AC%E6%8B%89%E6%9D%BE%E6%98%AF</p>
</blockquote>
<p>然后像这样解码:</p>
<pre><code>NSString* originalString =;
NSLog(@"====%@",originalString);
</code></pre>
<p><strong>输出是:</strong></p>
<blockquote>
<p>汉字马拉松是</p>
</blockquote></p>
<p style="font-size: 20px;">关于ios - 中文字符编码问题ios,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/14619316/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/14619316/
</a>
</p>
页:
[1]