IOS JSON turn plist
Read JSON data from the Xx.json file and write to the Xx.plist file with the following implementation code:
NSString *path = @ "/users/android_ls/desktop/city_province.json";
Nsarray *array = [nsjsonserialization jsonobjectwithdata:[nsdata Datawithcontentsoffile:path] Options: Nsjsonreadingmutableleaves Error:nil];
[Array writetofile:@ "/users/android_ls/desktop/city_province.plist" atomically:yes];
Note: The above code fragment must be run on the emulator
If you change the code snippet above to read:
NSString *path = [[NSBundle mainbundle] pathforresource:@ "City_province.json" oftype:nil];
MyLog (@ "path =%@", path);
Nsarray *array = [nsjsonserialization jsonobjectwithdata:[nsdata Datawithcontentsoffile:path] Options: Nsjsonreadingmutableleaves Error:nil];
NSString *newpath = [NSString stringwithformat:@ "%@%@", [[NSBundle Mainbundle] bundlepath],@ "/city_province.plist"];
MyLog (@ "NewPath =%@", NewPath);
[Array Writetofile:newpath atomically:yes];
Note: Copy the City_province.json file to the supporting files directory before testing
Put the test on the simulator and print the log as follows:
2014-10-15 22:38:03.224 ywbapp[11578:60b] path =/users/android_ls/library/application Support/iPhone Simulator/7.1/ Applications/0909d47b-a2b6-467d-9e19-396a73383d8a/ywbapp.app/city_province.json
2014-10-15 22:38:03.225 YWBAPP[11578:60B] NewPath =/users/android_ls/library/application Support/iphone simulator/7.1/applications/ 0909d47b-a2b6-467d-9e19-396a73383d8a/ywbapp.app/city_province.plist
Put the test on the real machine and print the log as follows:
2014-10-15 22:40:59.796 ywbapp[3127:60b] path =/var/mobile/applications/4dab17cc-f307-4d1b-b78d-80e9b5b4343f/ Ywbapp.app/city_province.json
2014-10-15 22:40:59.805 ywbapp[3127:60b] NewPath =/var/mobile/applications/ 4dab17cc-f307-4d1b-b78d-80e9b5b4343f/ywbapp.app/city_province.plist
The path is correct, but the file cannot be found in the appropriate directory.
Thank you for reading, I hope to help you, thank you for your support for this site!