2012-06-20 91 views
0

我想通過下面的代碼映射POST響應,但是當達到didLoadObjects時Restkit試圖映射相同的對象,因爲我試圖POST(發佈Foo並希望它映射Bar ,但RestKit試圖將返回映射到Foo)。Restkit映射POST迴應

[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

解決方案是設置rootKeyPath。

myPostReturnMapping.rootKeyPath = @"persons"; 

"persons": [ 
         { "id": "1", 
          "firstname": "hans", 
          "lastname": "maier", 
          "genre": "m" 
         }, 
         { "id": "2", 
          "firstname": "michael", 
          "lastname": "schmidt", 
          "genre": "w" 
         }]