Copyright ? 2017年ZaneWangWang. All rights reserved.
原文地址
一.網(wǎng)絡(luò)請求數(shù)據(jù)轉(zhuǎn)json文件
if ([responseObj[@"httpCode"] integerValue] == 200) {
NSDictionary *jsonDic = responseObj[@"data"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:0 error:nil];
NSString *filePath= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *newPath = [filePath stringByAppendingString:@"/hmkj_c_addressList.json" ];
[jsonData writeToFile:newPath atomically:YES];
//轉(zhuǎn)換成功后,文件位置要輸出出來便于查找
NSLog(@"newPath = %@", newPath);
}
二.json文件轉(zhuǎn).plist文件
1.拿以上輸出的文件位置,點擊finder,彈出如下圖:
2.繼續(xù)點擊前往,如下圖,并在前往文件夾中粘貼出剛剛輸出的路徑,注意不要.json文件名,因為進入的是文件夾.
3.將json文件拖入工程中,再寫如下代碼:
NSString *path = [[NSBundle mainBundle] pathForResource:@"hmkj_c_addressList.json" ofType:nil];
NSArray *array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] options:NSJSONReadingMutableLeaves error:nil];
NSString *str= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *plistPath = [str stringByAppendingString:@"/hmkj_c_addressList.plist" ];
//轉(zhuǎn)換成功后,文件位置要輸出出來便于查找
NSLog(@"plistPath = %@", plistPath);
[array writeToFile:plistPath atomically:YES];
4.然后然后按相同的找文件方式即可找到plist文件.
保留所有權(quán),未經(jīng)允許禁止轉(zhuǎn)載。