Reputation: 3
I need an app or an online converter like JSON Accelerator that generates Objective C classes from JSON strings. I had some issues with this app, some JSON's are converted OK others are not. There are a lot of properties, it would take ages to write them down manually and use tools like JSON Model or similar. Thanks in advance.
Upvotes: 0
Views: 2522
Reputation: 910
you can use thus toll to get objc object from json
and also you can use these mapper to get our result
https://github.com/aryaxt/OCMapper
Upvotes: 0
Reputation: 122458
You are much better off creating a class that can be initialized from an NSDictionary
and that way you can parse the JSON to an NSDictionary
, in the traditional way, and then create your class from that dictionary. You can also create arbitrary instances of the custom class and initialize the properties piece-meal.
@interface MyClass : NSObject
@property NSString *name;
@property NSUInteger age;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
@end
@implementation MyClass
- (instancetype)initWithDictionary:(NSDictionary *)dict
{
self = [super init];
if (self) {
_name = dict[@"name"];
_age = [dict[@"age"] unsignedInteger];
}
return self;
}
@end
Upvotes: 1