Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing json data on the iPhone: save the json string as it is VS make an object from json and use NSCoding + NSKeyedArchiver

In my iPhone application I get json data from a remote server, parse it using the Json Framework and present it in a UIview. Also want to be able to give the user the option to store the data on the device so that it can also be viewed offline. I was wondering if storing the json data directly is a better or worse choice than making an object and then saving it using NSCoding + NSKeyedArchiver. I assume that the advantage of storing a json string as it is, is that it takes less space on disc than an archived object while, on the other hand, by storing archived objects you don't have to parse the stored data every time thus using less memory.

Is there a best overall choice? Are there any best practices on that matter? The json files size is approximately 8KB.

like image 932
Kremk Avatar asked Feb 08 '11 14:02

Kremk


1 Answers

I use a different approach. Once the JSON data is parsed in my app, its stored in a NSDictionary. I persist that as a .plist file.

[myDictionary writeToFile:[self saveFilePath] atomically:YES];

To Load:

NSMutableDictionary *wholeDictionary = [NSDictionary dictionaryWithContentsOfFile:[self saveFilePath]];

That's it!

like image 195
Hiltmon Avatar answered Sep 24 '22 21:09

Hiltmon