json文件转为plist文件输出(及文件存放路径)

本文介绍了如何将JSON文件转换为plist文件,并探讨了iOS中不同类型的文件存储路径,包括关键数据、缓存数据、临时数据和离线数据的存放位置及管理策略。强调了遵循苹果规定的重要性,以避免App审核时因错误存储路径被拒。
摘要由CSDN通过智能技术生成

从xx.json文件中读取JSON数据,写入到xx.plist文件中,实现代码如下:

 

    NSString *path = @"/Users/apple/Desktop/testJtoP/testJtoP/1_category.json";
    NSArray *array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableLeaves error:nil];
    
    BOOL state = [array writeToFile:@"/Users/apple/Desktop/1_category.plist" atomically:YES];
    if(state){
        NSLog(@"成功");
    }else{
        NSLog(@"失败");
    }


ps:需在模拟器上运行

 

 

writeToFile写入不成功的原因 :

If an array or dictionary contains objects that are not property-list objects, then you cannot save and restore the hierarchy of data using the various property-list methods and functions.
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值