iphone - NSString 重音编码显示疯狂的字符

标签 iphone ios ipad encoding nsstring

我正在从服务器下载数据(文本)。

我尝试过:NSISOLatin1StringEncodingNSASCIIStringEncoding

但我不断看到类似以下内容:{"estado":"M\u00e9xico"}

请注意,它应为 México,而不是 M\u00e9xico(在 e 上带有重音符号)。

网上查了一下,我发现\u00e9实际上是é link.

但是 NSString 无法解释这一点,而是在我的 UILabels 上打印奇怪的东西:

enter image description here

我非常感谢您对此的帮助。

另外,如果您有兴趣,可以从这里下载数据:http://www.miorden.com/demo/iphone/estadoJSON.php

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.miorden.com/demo/iphone/estadoJSON.php"]];

NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

NSLog(@"Downloaded: %@", string);    

string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.miorden.com/demo/iphone/estadoJSON.php"] encoding:NSISOLatin1StringEncoding error:nil];

NSLog(@"Downloaded: %@", string);

我已经尝试了好几天了,这简直要了我的命!

非常感谢!

最佳答案

这似乎是 unicode,请尝试 NSUTF8StringEncoding。

关于iphone - NSString 重音编码显示疯狂的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7005981/

相关文章:

iphone - 通过addSubview添加后调用父UIViewController中的方法

iphone - 语义问题 : Use of undeclared identifier when adding Framework class references

javascript - 为什么在为 touchstart 事件调用 preventDefault() 时会抑制 onclick 事件?

iphone - quartz : Getting the diff images of two images

Iphone UIView 切换 : Previous view's subviews polluting newly switched-to view

iphone - iPhone 的暂停/恢复下载功能

ios - FaSTLane快照可以在真实的ios设备上运行吗?

ios - 如何在 swift 中进一步减少延迟时间?

ios - 奇怪的 UIView.animateWithDuration 编译错误如果在动画 block 中有一些代码

ios - UIMainScreen 不是 NativeScript iOS 函数错误