Object mapping in objective-c (iphone) by JSON

For my iPhone application, I use RESTful service and get JSON. I found libraries for deserializing this in an NSDictionary. However, I am wondering if there are any libraries for deserializing the JSON / NSDictionary / Property List into my object (arbitrary on my side).

The Java equivalent will be an object-relational matching, although sorting the objects I'm looking for is relatively simple (simple data types, complex relationships, etc.).

I noticed that Objective-C has an introspection, so theoretically this is possible, but I did not find a library for this.

Or is there an easy way to load an object from an NSDictionary / Property List object that does not need to be modified every time the object changes?

For example:

{ "id" : "user1", "name" : "mister foobar" "age" : 20 } 

loaded into an object

 @interface User : NSObject { NSString *id; NSString *name; int *age; } 
+6
json rest objective-c iphone orm
source share
3 answers

Take a look at the NSKeyValueCoding protocol. In particular, the methods setValuesForKeysWithDictionary : and dictionaryWithValuesForKeys:

+5
source share

I created a framework to do this automatically. Check it out.

https://github.com/dchohfi/KeyValueObjectMapping

+4
source share

Take a look at the Loid project on Sourceforge. I intend to provide what you are talking about.

Currently, the framework can reconstruct the meta description of the object (for example, your User object) and can be serialized to and from the LoidTypeData object. I intend to create an instance of LoidTypeData from the incoming JSON block, and then bind it to the object. Of course, there will be the opposite.

It is open source and GPL. You will need to access the code from SVN at the moment, I don’t quite know how to create a distribution for Mac.

- Frank

+1
source share

All Articles