为简单起见,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