Alexandru Nicolae
Alexandru Nicolae

Reputation: 3

Objective C class model generator from JSON

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

Answers (2)

Moktahid Al Faisal
Moktahid Al Faisal

Reputation: 910

you can use thus toll to get objc object from json

http://www.realmgenerator.eu/

and also you can use these mapper to get our result

https://github.com/aryaxt/OCMapper

Upvotes: 0

trojanfoe
trojanfoe

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

Related Questions