我正在从服务器下载数据(文本)。
我尝试过:NSISOLatin1StringEncoding
和 NSASCIIStringEncoding
但我不断看到类似以下内容:{"estado":"M\u00e9xico"}
请注意,它应为 México
,而不是 M\u00e9xico
(在 e 上带有重音符号)。
网上查了一下,我发现\u00e9
实际上是é
link.
但是 NSString 无法解释这一点,而是在我的 UILabels 上打印奇怪的东西:
我非常感谢您对此的帮助。
另外,如果您有兴趣,可以从这里下载数据: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/