爲簡單起見,Rest API發送這個JSON response-body = {「status」:「ok」}。Restkit 0.22.0如何映射一個沒有keyPath的簡單JSON響應來發布
我建立我的Restkit映射像...創建了一個名爲StatusResponse類具有一個@property (nonatomic, assign) NSString *status;
RKObjectMapping *statusResponseMapping = [RKObjectMapping mappingForClass:[StatusResponse class]];
[statusResponseMapping addAttributeMappingsFromDictionary:@{@"status":@"status"}];
// also tried : [statusResponseMapping addAttributeMappingsFromDictionary:@[@"status"]]; which resulted in same error
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *statusResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:statusResponseMapping method:RKRequestMethodPOST pathPattern:@"status" keyPath:nil statusCodes:statusCodes];
[[RKObjectManager sharedManager] addResponseDescriptor:statusResponseDescriptor];
I'm running a post which is successful, but I get this error back:
NSUnderlyingError=0x17024d440 "No mappable object representations were found at the key paths searched.", keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.}
response.body={
"status": "ok"
}
任何幫助,將不勝感激。
延遲應答道歉。我會嘗試你的建議。感謝分享。我會讓你知道我的結果。 – user3337849
謝謝。你的代碼確實有效。再次感謝... – user3337849