1

这是我的回复正文:

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

我想通过使用这个 keyPath:"bsqn.res" 来获得我真正需要的“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)];

但它给出了这个错误:

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

有没有办法做我想做的事?谢谢..

4

1 回答 1

1

在您的 JSON 中,bsqn.res不存在。bsqn只是一个字符串。

将您的响应描述符更改为keyPath:@"results",RestKit 会将结果数组中的每个项目映射到您的新实例TestResponse并设置res属性。

于 2013-11-06T16:14:39.803 回答