ios开发txt文件转plist文件

NSString *plistPath = [[NSBundle mainBundle]pathForResource:@"zujin" ofType:@"txt"];
//gbk编码 如果txt文件为utf-8的则使用NSUTF8StringEncoding
NSStringEncoding gbk = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
//定义字符串接收从txt文件读取的内容
NSString *str = [[NSString alloc]initWithContentsOfFile:plistPath encoding:gbk error:nil];
//将字符串转为nsdata类型
NSData *data = [strdataUsingEncoding:NSUTF8StringEncoding];
//将nsdata类型转为NSDictionary
NSDictionary *pDic = [NSJSONSerializationJSONObjectWithData:data options:kNilOptions error:nil];
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *plistPath1 = [paths objectAtIndex:0];
//得到完整的文件名
NSString *filename=[plistPath1 stringByAppendingPathComponent:@"zujin.plist"];
//输入写入
[pDic writeToFile:filename atomically:YES];

你可能感兴趣的:(ios开发txt文件转plist文件)