当我的 json 文件中有英文字符时,它会在数组中打印读取的 json,但是当我有藏文字符(utf8)时,它会打印 null。我正在粘贴我的 json 和 xcode 代码。请帮忙。这段代码是我从核心数据教程中尝试的
int main(int argc, const char * argv[])
{
@autoreleasepool {
// Create the managed object context
NSManagedObjectContext *context = managedObjectContext();
// Custom code here...
// Save the managed object context
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Error while saving %@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");
exit(1);
}
NSError* err = nil;
NSString* dataPath = [[NSBundle mainBundle] pathForResource:@"tsikzoe" ofType:@"json"];
NSDictionary* tsikzoe = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:dataPath]options:kNilOptions error:&err];
NSLog(@"Imported tsikzoe: %@",[tsikzoe objectForKey:@"wordDef"]);
}
return 0;
}
这是JSON
[{"id":1,"dictionaryType":1,"word":"༼༡༠༠༦༽ སྲོང་བཙན་ཆོས་ཀྱི་རྗེ་བོ་ཡབ་ཡུམ་གསུམ།","wordDef":"རྒྱལ་པོ་སྲུང་བཙན་སྒམ་པོ། བལ་བཟའ་ཁྲི་བཙུན། རྒྱ་བཟའ་ཀོང་ཇོ་བཅས་གསུམ་ལ་ཟེར།","dateSubmitted":"2012-08-19 00:00:00","author":2,"authorName":"དུང་དཀར་ཚིག་མཛོད།"},
{"id":2,"dictionaryType":1,"word":"༼༡༠༤༠༽ བསོ།","wordDef":"བསོ་བསོ་ཞེས་པའི་སྒྲའི་ཁྱད་པར་གྱི་མིང༌།","dateSubmitted":"2012-08-19 00:00:00","author":2,"authorName":"དུང་དཀར་ཚིག་མཛོད།"}]