Tuesday, February 28, 2012

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

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;
@end

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]


©2012 iPhone, iOS 5, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.

.
DeliciousTwitterTechnoratiFacebookLinkedInEmail

No comments: