1
當我是新來RestKit所以這個問題可能是愚蠢的使用:當使用[的ObjectManager使用SendObject:...],我怎麼告訴RestKit其映射應該使用的結果?更具體:我發送GET和POST數據到作爲回報與JSON編碼的消息響應的服務器:如何分辨RestKit哪個映射使用使用SendObject
{"purchaseresult":{"status":"ok","errormsg":""}}
我使用的Objective-C代碼如下所示:
RKObjectMapping *purchaseResultMapping = [RKObjectMapping mappingForClass:[PurchaseResult class]];
[purchaseResultMapping mapKeyPathsToAttributes:@"status", @"status", @"errormsg", @"errorMessage",nil];
[objectManager.mappingProvider setMapping:purchaseResultMapping forKeyPath:@"purchaseresult"];
[[RKObjectManager sharedManager].mappingProvider setErrorMapping:purchaseResultMapping];
[objectManager sendObject:queryParams toResourcePath:@"/purchase/post" usingBlock:^(RKObjectLoader* loader) {
loader.method = RKRequestMethodPOST;
loader.resourcePath = @"/purchase/post";
loader.params = queryParams;
loader.objectMapping = purchaseResultMapping;
}];
這將返回一個RestKit錯誤:
映射期間restkit.network:RKObjectLoader.m:216遇到錯誤:預期類型的「__NSDictionaryI」的對象映射,提供程序返回一個爲「PurchaseResult」
任何想法,我做錯了什麼?
感謝 基督教
這引出了下一個問題;-):有沒有將數據發送到後端*無*號不必定義的映射一個更聰明的方式?其實,我只需要一個映射這個調用的結果。 PS:數據必須作爲POST參數發送。 – itsame69
我已經更新了我的答案。你仍然需要定義用於接收對象的映射,但你可以發送參數的普通字典。 – danielM
非常感謝Daniel!這解決了問題! – itsame69