我想使用 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 正文:{"objects":[{"title":"TestTitle"}]}
服务器无法识别这一点。我需要能够获得以下格式:
HTTP 正文:"objects":[{"title":"TestTitle"}]
请帮忙,过去两天这一直让我发疯。