Object mapping in objective-c (iphone) from JSON
- by freshfunk
For my iPhone app, I'm consuming a RESTful service and getting JSON. I've found libraries to deserialize this into an NSDictionary. However, I'm wondering if there are any libraries to deserialize the JSON/NSDictionary/Property List into my object (an arbitrary one on my side).
The java equivalent would be the object-relational mappers although the sort of object mapping I'm looking for is relatively straightforward (simple data types, no complex relationships, etc.).
I noticed that Objective-C does have introspection so it seems theoretically possible but I haven't found a library to do it.
Or is there a simple way to load an object from an NSDictionary/Property List object that doesn't require modification every time the object changes?
For example:
{ "id" : "user1",
"name" : "mister foobar"
"age" : 20 }
gets loaded into object
@interface User : NSObject {
NSString *id;
NSString *name;
int *age;
}