iOS开发之JSON转PLIST(把存储json格式的文件转换成plist文件)

有时开发过程当中,常常须要调试接口,可是可能常常没有网络,致使调试没法正常进行。json

 

对此能够本身手动设置一些假数据,也能够经过计算机来为咱们保存一份真实的网络数据,并本身转化成plist数据,存在本地使用。网络

 

 

 

## 直接在Mac上运行post

```objcatom

 

NSString *path = @"/Users/xiaoyou/Desktop/lot.json";  spa

NSArray *array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableLeaves error:nil];  调试

[array writeToFile:@"/Users/xiaoyou/Desktop/lot.plist"atomically:YES]; orm

   

   

```blog

 

## 直接在模拟器上运行接口

 

 

```objc开发

NSString *path = [[NSBundle mainBundle] pathForResource:@"lot.json" ofType:nil];  

  

NSArray *array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableLeaves error:nil];  

  

NSString *newPath = [NSString stringWithFormat:@"%@%@",[[NSBundle mainBundle] bundlePath],@"/lot.plist" ];  

  

[array writeToFile:newPath atomically:YES];  

 

```

 

 

踏实的学点东西,让本身丰富,也让生活丰富和充实。
相关文章
相关标签/搜索