I want to save the following NSDictionary to a MySQL database:
NSDictionary notesDictionary:
object: NSString key:"note"
object: NSArray key:'subNotes"
object: NSString key:"publishDate"
The tricky part is that the NSArray subNotes is just another array of dictionaries with the same keys as above. So a note is put in a dictionary, which in turn has an array of dictionaries, which in turn has an array of dictionaries, and so on (each note has a subnote, and subnotes have subnotes, and so on).
I’m new to MySQL, so the following is the solution I’ve found to storing the above dictionary in the database:
NSString *jsonString = [notesDictionary JSONRepresentation];
Then I just store the string into the database, and retrieve it with similar methods. This works, but I’m not sure if it scales. If I had a 1000 notes, would this cause any performance setbacks, as the entire dictionary is saved as a string, and then later converted from a string back to a dictionary. Is this a good, fast, and secure way? Or is there something else I should be looking into?
JSON is a perfectly good serialization format. I wouldn’t worry about performance or anything like that. The only concern I’d have is making sure the MySQL column is set up to take an arbitrarily long string. (Not sure how to do that in MySQL offhand, but it shouldn’t be too tough.)