0
votes

I have the following two classes:

// Animal.h
@interface Animal : NSObject {
    NSString *name;
    NSString *description;
}

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;

@end

and

// Group.h
@interface Group : NSObject {
    NSMutableArray<Animal> *list;
}

@property (nonatomic, retain) NSMutableArray<Animal> *list;

@end

I want to convert a NSString with all Group info into a Group object, add a new Animal object into the NSMutableArray and convert it again to string to send it back to the server.

That should be pretty straight forward, but I cannot fin the way to serialize/deserialize the object. I tried using JSNModel but I couldn't make it work.

Can somebody help me, please? Thanks in advance!

1

1 Answers

0
votes

Use the SBJson framework: https://github.com/SBJson/SBJson

#import "SBJson.h"
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString *jsonString = [writer stringWithObject:arr];

You'll get a JSON string. That should be all good.