iOS 服務(wù)器json數(shù)據(jù)轉(zhuǎn)成.json文件再轉(zhuǎn)成.plist文件

Copyright ? 2017年ZaneWangWang. All rights reserved.

原文地址

一.網(wǎng)絡(luò)請(qǐng)求數(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)換成功后,文件位置要輸出出來(lái)便于查找

NSLog(@"newPath = %@", newPath);

}

二.json文件轉(zhuǎn).plist文件

1.拿以上輸出的文件位置,點(diǎn)擊finder,彈出如下圖:


2.繼續(xù)點(diǎn)擊前往,如下圖,并在前往文件夾中粘貼出剛剛輸出的路徑,注意不要.json文件名,因?yàn)檫M(jìn)入的是文件夾.

3.將json文件拖入工程中,再寫(xiě)如下代碼:

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)換成功后,文件位置要輸出出來(lái)便于查找

NSLog(@"plistPath = %@", plistPath);

[array writeToFile:plistPath atomically:YES];

4.然后然后按相同的找文件方式即可找到plist文件.

保留所有權(quán),未經(jīng)允許禁止轉(zhuǎn)載。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容