我从URL获取文本数据,并且有一个特定字符似乎无法正确编码 - > ȭ
我知道那个角色是什么,所以我尝试手动将其编码为utf-8,但xcode甚至不识别该角色
NSLog(@"before: %@", brokenCharacter);
if([brokenCharacter isEqualToString: @"ȭ"]) brokenCharacter = @"A";
NSLog(@"after: %@", brokenCharacter);
我将NSLog视为:
before: ȭ
after: ȭ
这个问题会有解决办法吗?
答案 0 :(得分:0)
可以使用NSUTF16BigEndianStringEncoding
作为编码参数
NSString *brokenCharacter = @"ȭ";
NSLog(@"before: %@", brokenCharacter);
NSData *dataCharacter = [brokenCharacter dataUsingEncoding:NSUTF16BigEndianStringEncoding];
brokenCharacter = [NSString stringWithUTF8String:[dataCharacter bytes]];
NSLog(@"after: %@", brokenCharacter);