如何将encode编码成可读字符串?

时间:2015-04-15 09:33:18

标签: ios objective-c xcode encoding encode

我从URL获取文本数据,并且有一个特定字符似乎无法正确编码 - > ȭ

我知道那个角色是什么,所以我尝试手动将其编码为utf-8,但xcode甚至不识别该角色

NSLog(@"before: %@", brokenCharacter);
if([brokenCharacter isEqualToString: @"ȭ"]) brokenCharacter = @"A";
NSLog(@"after: %@", brokenCharacter);

我将NSLog视为:

before: ȭ
after: ȭ

这个问题会有解决办法吗?

1 个答案:

答案 0 :(得分:0)

可以使用NSUTF16BigEndianStringEncoding作为编码参数

NSString *brokenCharacter = @"ȭ";
NSLog(@"before: %@", brokenCharacter);
NSData *dataCharacter = [brokenCharacter dataUsingEncoding:NSUTF16BigEndianStringEncoding];
brokenCharacter = [NSString stringWithUTF8String:[dataCharacter bytes]];
NSLog(@"after: %@", brokenCharacter);