objective-c - NSMutableString 和(字符)编码问题 : getting\U00fc in case of ü

标签 objective-c ios encoding character-encoding nsmutablestring

我正在从 coreData 获取我的实体并将 fetchrequest 的结果保存到 NSMutableString 以进行文本到语音的转换。

self.ttsInboxCards = [[NSMutableString alloc] initWithString:@""];  
[self.ttsInboxCards appendString:[[entitySetsCards valueForKey:@"cardTitle"] description]];

在 NSLog 中我得到了这个值:

F\U00fcr | schl\U00e4ge | zuh\U00f6ren  

应该是:

Für | schläge | zuhören  

我已经尝试了很多方法来获得正确的编码,例如:

stringWithUTF8String:  

等等,但没有任何效果。

我怎样才能避免这个问题?

编辑 1:

我像这样从 coreData 获取值:
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"EntitySetsCardsInbox" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

NSPredicate *inboxPred = [NSPredicate predicateWithFormat:@"archived == 0 AND cardId != 0"];


[fetchRequest setPredicate:inboxPred];

NSSortDescriptor *sortDescriptor2 = [[[NSSortDescriptor alloc] initWithKey:sortString ascending:sortAsc selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];
NSArray *sortDescriptors = [[[NSArray alloc] initWithObjects:sortDescriptor2, nil] autorelease];
[fetchRequest setSortDescriptors:sortDescriptors];

NSError *error = nil;
NSArray *cardTitles = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];



[self.ttsInboxCards appendString:[[cardTitles valueForKey:@"cardTitle"] description]];

文字转语音

    if (isSpeaking) {
    [vocalizer cancel];
    isSpeaking = NO;
}
else {
    isSpeaking = YES;
    vocalizer = [[SKVocalizer alloc] initWithLanguage:@"de_DE" delegate:self];
    [vocalizer speakString:tmp];


}

最佳答案

我写道:

cardTitles is an array. So, invoking -valueForKey: on it yields an array built by invoking -valueForKey:@"cardTitle" on each element. Then you're asking that array for its description. It's very likely to do formatting of its contents.

brush51 写道:

componentsJoinedByString: worked and solved the issue with encoding. now i have to split them correctly so that i can use it cleanly for text to speech. can you make an answer with that so i can mark this question as answered and others can find it faster

关于objective-c - NSMutableString 和(字符)编码问题 : getting\U00fc in case of ü,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10086744/

相关文章:

iOS Cocoa UITableView 旋转后的位置

ios - swift:监听 "struct variable"-change 事件?

ios - ECSlidingViewController 和测试

ios - 无法在请求正文中添加多张图片

matlab - MATLAB 源文件中的 Unicode 字符

objective-c - MFMailComposeViewController 抛出 viewServiceDidTerminateWithError 并在使用自定义标题字体时退出

objective-c - Cocoa应用程序,如何在应用程序未运行时显示徽章标签?

ios - 单击 UITableview 行后 UIActivityIndi​​catorView 不显示?

c# - 字节串在python和c#中是相同的,但是md5 hashcode是不同的

php - 如何使用 php 从 mysql 推送 latin-2 字符