1
votes

This is my response body:

{
  "bsqn": 5,
  "results": [
    {
      "sqn": 1,
      "res": "oldu!"
    }
  ]
}

I wanna get through for "res" property which i really need, by using this keyPath:"bsqn.res"

//TestResponse.h
@interface TestResponse : NSObject

@property (nonatomic, copy) NSString *res;

+ (RKObjectMapping *)objectMapping;

@end

// TestResponse.m
@implementation TestResponse

+ (RKObjectMapping *)objectMapping
{
    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[self class]];
    [mapping addAttributeMappingsFromDictionary:@{@"res": @"res"}];

    return mapping;
}

@end


RKResponseDescriptor *newDesc = [RKResponseDescriptor responseDescriptorWithMapping:    
[TestResponse objectMapping] method:RKRequestMethodPOST pathPattern:nil keyPath:@"bsqn.res"     
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

But it gives this error:

this class is not key value coding-compliant for the key hashcode

Is there a way to do what i want? Thanks..

1
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[self class]]; I think [self class] should be changed to self since you are calling this in class method.Eimantas

1 Answers

1
votes

In your JSON, bsqn.res doesn't exist. bsqn is just a string.

Change your response descriptor to keyPath:@"results" and RestKit will map each item in the results array into a new instance of your TestResponse and set the res property.