2013-05-07 167 views
1

我想發送一個對象到服務器(PUT請求)沒有映射,因爲我已經有了我需要從服務器的一切。即使服務器已成功創建對象,回調也會直接失敗。RestKit 0.20忽略putObject:映射

下面是我在做什麼的例子:

- (void) PUTsuccess:(void (^)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult))success 
      failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure 
{ 
    RKObjectManager *objectManager = [YSManager objectManager]; 
    [objectManager putObject:self path:[kPutPath stringByAppendingString:self.id] parameters:kAPIDefaultParameters success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { 
      NSLog(@"operation.HTTPRequestOperation.request.HTTPBody: %@", [[NSString alloc] initWithData:operation.HTTPRequestOperation.request.HTTPBody encoding:NSUTF8StringEncoding]); 
      if (success) { 
       success(operation, mappingResult); 
      } 
     } 
     failure:^(RKObjectRequestOperation *operation, NSError *error) { 
      NSLog(@"Failure! Error: %@", error.localizedDescription); 
     if (failure) { 
      failure(operation, error); 
     } 
    }]; 
} 

在201創建的服務器響應,我可以在服務器找回我的對象​​,這樣一切都很好,不過,回調直接觸發故障因爲它試圖映射我的對象,故障回調中的錯誤是:

Error: No response descriptors match the response loaded. 

非常感謝,任何建議將不勝感激!

更新1 增補字典現在映射:

RKObjectMapping *idMapping = [RKObjectMapping requestMapping]; 
    [idMapping addAttributeMappingsFromArray:@[]]; 
    RKResponseDescriptor *responseDescriptorID = [RKResponseDescriptor responseDescriptorWithMapping:idMapping 
                         pathPattern:[kRequestPath stringByAppendingString:@":code"] 
                          keyPath:@"objects" 
                         statusCodes:statusCodes]; 
+1

嘗試使用keyPath:nil並仔細檢查pathPattern。 – Roger 2013-05-07 23:49:05

回答

1

定義響應描述符只是以映射響應(或它的一部分),以一個NSDictionary。

+0

好吧我現在這樣做了,但我現在得到的錯誤是:錯誤:在搜索到的關鍵路徑上找不到可映射的對象表示。查看源代碼的問題。 – 2013-05-07 21:29:47

+0

聲音像路徑模式是正確的,但描述符的關鍵路徑是錯誤的。 JSON的迴應是什麼? – Wain 2013-05-07 23:01:51

+0

謝謝!這是問題所在。愚蠢的我工作到很晚我猜...再次感謝! – 2013-05-08 06:35:28