Featured iPhone Development Resources

Open Source: Library For Automatic Serialization/Deserialization To And From JSON Dictionaries

Some time ago I mentioned the excellent library allowing you to save any object to a Plist file.

Today I came across a library allowing you to automatically take JSON dictionaries, or property lists and turn them into model objects (or vice versa).

Here’s an example from the Github page demonstrating what makes this library so interesting.

You can take a JSON dictionary like this:

 "userID" : 1234,
 "name" : "Jane Smith",
 "likes" : ["swimming", "movies", "tennis"],
 "invitedBy" : {
 "userID" : 9876,
 "name" : "Bob Willis"

And out comes a model object like this:

 @interface User : NSObject
 @property (assign) int userID;
 @property (copy) NSString *name;
 @property (strong) NSArray *likes;
 @property (strong) User *invitedBy;

The library is JAGPropertyConverter from James Gill, and you can download the library and find further information on usage on the Github page here.

Definitely a very useful looking library.

[via @romainbriche]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.