在mac环境中将上面的excel转成plist:
1.将表格拷贝到文本编辑器中,去除掉第一行的Countries and Regions, 国家或地区, 国际域名缩写,电话代码,时差等文字(注意,最后一行也不能留空白,否则代码转换会读取不到,发生崩溃)
2.在文本编辑器中按下快捷键:shift⇧+command⌘+T.
再保存的时候就会出现(转换成utf-8编码):
3.将保存的文件加入工程中,并使用如下代码进行转换
NSString*alarmPath = [[NSBundlemainBundle]pathForResource:@"countrycode"ofType:@"txt"];
//NSLog(@"%@",alarmPath);
//尝试更换文件编码,失败
//NSStringEncoding gbk = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString*alarmContent = [[NSStringalloc]initWithContentsOfFile:alarmPathencoding:NSUTF8StringEncodingerror:nil];
//NSLog(@"%@",alarmContent);
NSArray*alarmArray = [alarmContentcomponentsSeparatedByCharactersInSet:[NSCharacterSetnewlineCharacterSet]];
//NSLog(@"%@",alarmArray);
NSString*docuPath = [NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
NSString*plistPath = [docuPathstringByAppendingPathComponent:@"countryCode.plist"];
NSLog(@"%@",plistPath);
NSMutableArray*resultsArr = [NSMutableArrayarray];
for(NSIntegerj =0; j < alarmArray.count; j++){
NSString*alarmStr = [alarmArrayobjectAtIndex:j];
//NSLog(@"%@",alarmStr);
NSArray*alarmArr = [alarmStrcomponentsSeparatedByString:@"\t"];
[resultsArraddObject:@{@"country":[alarmArrobjectAtIndex:0],@"Chinese":[alarmArrobjectAtIndex:1],@"abbr":[alarmArrobjectAtIndex:2],@"code":[alarmArrobjectAtIndex:3],@"jetLag":[alarmArrobjectAtIndex:4]}];
}
[resultsArrwriteToFile:plistPathatomically:YES];
结束;