Object mapping in objective-c (iphone) from JSON

Posted by freshfunk on Stack Overflow See other posts from Stack Overflow or by freshfunk
Published on 2010-04-13T03:35:38Z Indexed on 2010/04/13 3:43 UTC
Read the original article Hit count: 779

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;
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c