Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UTF8的愚蠢问题_Objective C_Plist - Fatal编程技术网

Objective c UTF8的愚蠢问题

Objective c UTF8的愚蠢问题,objective-c,plist,Objective C,Plist,这是一个愚蠢的n00b问题,但我就是不能让它起作用。我确实认为我需要转换为NSString并利用“stringWithUTF8String:”,但我不知道如何在这段代码中实现它,所以我在NSLog中得到了正确的输出。我一直在四处寻找,但它仍然不起作用。plist是正确的 我的输出是: 2010-11-07 21:43:00.419 plist_test[2984:207] Förbered och skriv 2010-11-07 21:43:00.425 plist_test[2984:2

这是一个愚蠢的n00b问题,但我就是不能让它起作用。我确实认为我需要转换为NSString并利用“stringWithUTF8String:”,但我不知道如何在这段代码中实现它,所以我在NSLog中得到了正确的输出。我一直在四处寻找,但它仍然不起作用。plist是正确的

我的输出是:

2010-11-07 21:43:00.419 plist_test[2984:207] Förbered och skriv  
2010-11-07 21:43:00.425 plist_test[2984:207] KLART  
2010-11-07 21:43:00.425 plist_test[2984:207] LÄS IN PLIST  
2010-11-07 21:43:00.427 plist_test[2984:207] array2: (  
    ETT,    
    "TV\U00c5",  ========Here is the problem, should be "TVÅ"    
    TRE,  
    FYRA  
)
这是我正在使用的代码

- (void)viewDidLoad {

NSLog(@"Förbered och skriv");

NSMutableArray *array = [[NSMutableArray alloc] init];  
[array addObject:@"ETT"];  
[array addObject:@"TVÅ"];  
[array addObject:@"TRE"];  
[array addObject:@"FYRA"];  

[array writeToFile:@"/Users/PeterK/Desktop/plisttest.plist" atomically: TRUE];


NSLog(@"KLART");


NSLog(@"LÄS IN PLIST");

NSMutableArray *array2 = [[NSMutableArray alloc] init];

array2 = [NSMutableArray arrayWithContentsOfFile:@"/Users/PeterK/Desktop/plisttest.plist"];

NSLog(@"array2: %@", array2); ====here is the output


[super viewDidLoad];
}
表示代码中的目标c字符串文字严格为7位ASCII。 (编辑:它们不是严格意义上的7位ASCII,但7位ASCII以外的任何东西都意味着它们是每个模块的,并且没有链接到静态数据部分,这可能会导致内存膨胀。换句话说,除非是内存负担,否则就使用它。)


您可以通过该方法从数据中加载字符串。

Objective-C字符串文字并不是严格意义上的7位ASCII,如您的示例所示。但是,为了保持一致性和兼容性,您应该避免使用7位ASCII以外的任何东西

下面的工作是使用Unicode安全地加载字符串

+ (id)stringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error;
+ (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error;

本地化字符串用于多语言接口。将显示的文本与显示的按钮分开,诸如此类。

这些字符串是否已正确序列化到文件中?我看起来没问题:我得到以下输出:2010-11-09 19:04:17.722 plist_test[684:207]LÄS IN plist 2010-11-09 19:04:17.729 plist_test[684:207]text:ETT TVÅTRE FYRA您正在尝试加载plist文件,这就是xml内容。是的,这是NSString的正确输出。如果要加载它,可以使用NSDictionary dictionaryWithContentsOfFile,然后导航生成的树。