I would like to map a json string to an anonymous object using the specific class. Suppose i have a country class. I would like to parse a json string into this object without knowing which object it is. So i use the class for parsing.
@interface CountryModel
@property (assign, nonatomic) int id;
@property (strong, nonatomic) NSString* country;
@end
NSString* json = (fetch here JSON from Internet) ...
CountryModel* country ;
id obj = country ;
obj = tojson( [obj class] , json )
https://github.com/icanzilb/JSONModel does what i need but i need same thing without using the inheritance. I would like to do same thing without inheriting from JSONModel;
You could define a Category for your custom model class (say,
CountryModel
) which implements a class factory method. A contrived example:jsonObject is a representation of a JSON Object as a
NSDictionary
object. You need to first create this representation before passing it the class factory method, e.g.: