我有以下两个类:
// Animal.h
@interface Animal : NSObject {
NSString *name;
NSString *description;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@end
和
// Group.h
@interface Group : NSObject {
NSMutableArray<Animal> *list;
}
@property (nonatomic, retain) NSMutableArray<Animal> *list;
@end
我希望将包含所有Group信息的NSString转换为Group对象,将新的Animal对象添加到NSMutableArray中,然后将其再次转换为字符串以将其发送回服务器。
这应该是非常简单的,但我无法完成序列化/反序列化对象的方式。我尝试使用JSNModel,但我无法使其正常工作。
是的,有人可以帮助我吗? 提前谢谢!答案 0 :(得分:0)
使用SBJson框架:http://sbjson.org/
#import "SBJson.h"
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString *jsonString = [writer stringWithObject:arr];
你会得到一个JSON字符串。这应该都很好。