JSON数据转plist文件

在工作中,经常有某些固定的值,这些值通常是不会变的,存数据库----麻烦,存本地,这个可以,不过还要在项目中走一次网络请求来获取数据,不如生成一个plist方便.下面教大家把JSON数据转成plist文件的方法

[NetworkHandler getDataByURLString:@"http://app.crhclub.com/v30/flight.ashx?action=airlineCode" BodyString:nil WithDataBlock:^(id result) {
        
        
            
            NSDictionary *jsonDic = result;
            
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:0 error:nil];
            
            NSString *filePath= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
            
            NSString *newPath = [filePath stringByAppendingString:@"/MaXiaoshuai.json" ];
            
            [jsonData writeToFile:newPath atomically:YES];
            NSLog(@"newPath = %@", newPath);

// 将json数据转成json文件
    

            
            NSArray *array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:newPath] options:NSJSONReadingMutableLeaves error:nil];
            NSString *newPlistPath = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] bundlePath],@"/MaXiaoshuai.plist" ];
            [array writeToFile:newPlistPath atomically:YES];
            NSLog(@"newPlistPath = %@", newPlistPath);

     
        
    } WithErrorBlock:^(id result) {

    }];
            ```
 command + shift + G  输入newPlistPath的地址 就可以获取plist文件,拖到项目玩耍去吧
生命不息,代码不止!码农一枚,请多点赞

等等!!!等等!!!如果懒得自己写,下面这个工具送给你,输入json数据直接转plist文件

链接: https://pan.baidu.com/s/1i4BNXel 密码: qghh


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,895评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,263评论 4 61
  • 看清楚一个问题,以及问题背后的原因,都不是一个点能说清楚的需要进行多维的分析。我现在看文章很费力,需要用到储蓄知识...
    梅启林阅读 190评论 0 1
  • 今天时间晚了,拍看的两页书,坚持,加油。懒癌必杀!
    三河散人阅读 256评论 2 2
  • 山一程 水一程 依然爱你
    冷风中啊阅读 220评论 0 0