我想用restkit发布以下信息到服务器:
[
{ "title": "cvxcv" },
{ "title": "sdfsdf" },
{ "title": "qsfqsdqsd" }
]
我定义了以下两个类:
@interface ObjectTemplate : NSObject
@property (nonatomic, copy) NSString *title;
@end
@interface ObjectListTemplate : NSObject
@property (nonatomic, strong) NSArray *objects;
@end
它们的映射如下:
// Object template
RKObjectMapping *objectTemplateMapping = [RKObjectMapping mappingForClass:[ObjectTemplate class]];
[objectTemplateMapping mapAttributes:@"title", nil];
[_objectManager.mappingProvider setSerializationMapping:[objectTemplateMapping inverseMapping] forClass:[ObjectTemplate class]];
// Object list template
RKObjectMapping *objectListTemplateMapping = [RKObjectMapping mappingForClass:[ObjectListTemplate class]];
[objectListTemplateMapping mapKeyPath:@"objects" toRelationship:@"objects" withMapping:objectTemplateMapping];
RKObjectMapping *inverseObjectListTemplateMapping = [objectListTemplateMapping inverseMapping];
[_objectManager.mappingProvider setSerializationMapping:inverseObjectListTemplateMapping forClass:[ObjectListTemplate class]];
问题是,我得到一个根节点每当张贴或放置一个objectListTemplate到服务器:
HTTP身体:{"对象":[{"标题":"TestTitle"}]}
服务器无法识别。我需要能够得到以下格式:
HTTP身体:"对象":[{"标题":"TestTitle"}]
请帮帮我,这两天我都快疯了
你应该能够离开ObjectListTemplate
, post一个NSArray和定义内部映射。RESTkit应该意识到它是一个数组,并将其对象映射到定义的映射,这应该以您想要的方式结束。