IPhone + JSON + Reflection

I am writing an iphone application with JSON and am trying to turn JSON strings into objects (NOT Dictionaries or Arrays).

In Java, thanks to Reflection, I can easily turn JSON into javabean instances like this:

import net.sf.json.JSONObject;
class MyBean {
    private String property;
    public String getProperty() { return property; }
    public void setProperty(String property) { this.property=property; }
}

// turn JSON string into a MyBean instance
String str = "{\"property\":\"some value\"}";  
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( str );
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setRootClass( MyBean.class );
MyBean instance = (MyBean) JSONSerializer.toJava( jsonObject, jsonConfig );

I was wondering if this is possible in objective-c. I am currently using this JSON structure, but I wish to switch if necessary.

Thanks,

+5
source share
4 answers

objectiveresource objectivesupport. Objective-C , ActiveResource ActiveSupport Ruby RESTful. , , JSON ( XML). , , / NSObject. , , : ( NSObject, NSArray NSDictionary)  http://github.com/yfactorial/objectivesupport/tree/d08b5be6c0f7a2b0196b6ec17e4441bb146c4e23/Classes/lib/Serialization/JSON

, , , JSON framework, .

+4

, Objective-C Runtime Reference

(, class_createInstance object_setInstanceVariable), .

0

, - , , , , : JSON iPhone .

0

All Articles