Restkit 0.22.0 how to draw a simple JSON response without keyPath for publishing

For simplicity, Rest, the API sends this response body JSON = {"status": "ok"}.

I am setting up my Restkit mappings, for example ... created a class called StatusResponse that has one @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"
}

Any help with this would be appreciated.

+4
source share
2 answers

You should try keyPath for @ "" and pathPattern as zero, here is the part of the code I use that works fine for me. I am doing the same thing you are trying to do.

RKResponseDescriptor *statusResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[ResponseStatus rkObjectMappingForResponse:YES] method:RKRequestMethodAny pathPattern:nil keyPath:@"" statusCodes:statusCodes];
+3
source

pathPattern:@"status", status . , , .

, pathPattern:nil.

0

Source: https://habr.com/ru/post/1536878/


All Articles