首页 > 用 NSBundle mainBundle 读取出来的Json文件 怎么修改后进行本地存储

用 NSBundle mainBundle 读取出来的Json文件 怎么修改后进行本地存储

我是用下面方法读取的数据

NSString * path;
path = [[NSBundle mainBundle]pathForResource:@"allStation" ofType:@"json" ];
NSData * jsonData = [[NSData alloc] initWithContentsOfFile:path];

id JsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];


修改后的 JsonObject数据   用下面的方法进行本地存储 显示成功 但是保存到了沙盒内 没有保存到程序的main bundle中 请教一下 为什么 怎么样可以保存到程序的main bundle 文件中 希望提供一下可以执行的代码
    NSData *jsonData1 = [NSJSONSerialization dataWithJSONObject:JsonObject options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData1 encoding:NSUTF8StringEncoding];
NSLog(@"%@", jsonString);
  BOOL res1=[jsonString writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
if (res1) {
    NSLog(@"文件写入成功");
}else{
    NSLog(@"文件写入失败");

};


哈哈,没办法写到 main bundle 的~ bundle 是你 app 安装时打的包里带的 > < 它是只读的。你要存只能存到沙盒里。

【热门文章】
【热门文章】