我正在学习RestKit,并希望使用对象映射器POST一个有效负载。我正在使用registerMapping:但这会在根密钥上创建映射。有没有办法将对象映射到资源?我的映射代码如下所示:
[self.objectManager.router routeClass:[Session class] toResourcePath:@"/sessions" forMethod:RKRequestMethodPOST];
[self.objectManager.mappingProvider registerMapping:[Session mappingForObjectStore:self.objectManager.objectStore]
withRootKeyPath:@""];
[self.objectManager postObject:session usingBlock:^(RKObjectLoader *loader) {
loader.resourcePath = @"/sessions";
loader.delegate = self;
}];
创建这样的有效负载:
{ “”:{data:“stuff”} }
但我正在追踪这样的有效载荷:
{ 数据:“东西” }
什么是RestKit方式?
答案 0 :(得分:0)
Blake指出我使用了一个我忽略的API。所以我将registerMapping替换为:
[self.objectManager.mappingProvider setObjectMapping:[Session mappingForObjectStore:self.objectManager.objectStore]
forResourcePathPattern:@"/sessions"];
[self.objectManager.mappingProvider setSerializationMapping:[[Session mappingForObjectStore:self.objectManager.objectStore] inverseMapping]
forClass:[Session class]];
三个欢呼!