DB文件转化json文件转化成plist文件

今天遇到一个问题,就是很多文件都是DB格式的,我们iOS开发需要将这个文件转化成我们需要的文件,首先如果你是苹果本下载SQLPro forSQLite软件,然后你就会打开一切DB文件,不需要任何辅助就能以json的格式导出,这样我们就可以用了,但是如果还觉得不够爽的话,就根据代码吧json转化成plist文件简单么

    NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"cityaddres2" ofType:@"json"];
    NSData *data = [[NSFileManager defaultManager] contentsAtPath:dataPath];
    NSError *error;
    NSArray *questionnaireArr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionaryWithCapacity:10];
    for (int i = 0; i < questionnaireArr.count; i ++) {
        NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithCapacity:10];
        NSMutableArray *dataArr = [NSMutableArray arrayWithCapacity:10];
        for (int j = 0; j < [questionnaireArr[i][@"city"] count]; j ++) {
            [dic2 setObject:questionnaireArr[i][@"city"][j][@"area"] forKey:questionnaireArr[i][@"city"][j][@"name"]];
        }
        [dataArr addObject:dic2];
        [dic1 setObject:dataArr forKey:questionnaireArr[i][@"name"]];
       
    }
    NSString *cachePatch = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *filePath = [cachePatch stringByAppendingPathComponent:@"newCity.plist"];

你可能感兴趣的:(DB文件转化json文件转化成plist文件)