我试图通过下面的代码映射POST响应,但是当到达didLoadObjects时,Restkit试图映射同一个对象,因为我正在尝试POST(发布Foo并希望它映射Bar,但RestKit是试图将回报映射到Foo)。
[self.objectManager sendObject:mySyncInstance toResourcePath:url usingBlock:^(RKObjectLoader* postLoader) {
postLoader.delegate = aDelegate;
postLoader.objectMapping = [self.objectManager.mappingProvider objectMappingForClass:[Bar class]];
postLoader.method = RKRequestMethodPOST;
postLoader.userData = kUserDefaultsAttendanceReads;
postLoader.serializationMIMEType = RKMIMETypeJSON;
postLoader.serializationMapping
[postLoader setUsername:[prefs objectForKey:kCurrentUsername]];
[postLoader setPassword:[prefs objectForKey:kCurrentPassword]];
}];// end sendObject
答案 0 :(得分:0)
解决方案是设置rootKeyPath。
myPostReturnMapping.rootKeyPath = @"persons";
"persons": [
{ "id": "1",
"firstname": "hans",
"lastname": "maier",
"genre": "m"
},
{ "id": "2",
"firstname": "michael",
"lastname": "schmidt",
"genre": "w"
}]