NSDictionary 描述不返回 utf8 字符? [英] NSDictionary description not returning utf8 characters?

查看:61
本文介绍了NSDictionary 描述不返回 utf8 字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以 utf8 字符串作为对象的 NSDictionary.打印对象会打印出它们应有的特殊字符.

I have an NSDictionary with utf8 strings as objects. Printing the objects prints the special characters as they should.

但是当我使用 description 方法将字典转换为字符串时,utf8 字符无法正确打印出来.

But utf8 characters do not get correctly printed out when I convert the dictionary to a string with the description method.

NSDictionary *test = [NSDictionary dictionaryWithObject:@"Céline Dion" forKey:@"bla"];
NSLog(@"%@",[test objectForKey:@"bla"]); // prints fine
NSLog(@"%@",test);                       // does not print fine, é is replaced by \U00e
NSLog(@"%@",[test description]);         // also does not print fine

如何在保留 utf8 字符的同时打印 NSDictionary?

How can I print the NSDictionary while preserving utf8 characters?

推荐答案

我不关心 -description 做什么,它只是为了调试.

I wouldn't worry about what -description does, it's just for debugging.

从技术上讲,您没有 UTF-8 字符串.您有字符串(它们是 Unicode).你不知道 NSString 内部使用什么,你不应该关心.如果你想要一个 UTF-8 字符串(比如你传递给 C API 时),请使用 -UTF8String.

Technically, you don't have UTF-8 strings. You have strings (which are Unicode). You don't know what NSString uses internally, and you shouldn't care. If you want a UTF-8 string (like when you're passing to a C API), use -UTF8String.

这篇关于NSDictionary 描述不返回 utf8 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆