Restkit对象映射

时间:2013-05-25 19:38:41

标签: ios objective-c rest restkit restkit-0.20

我正在努力尝试映射以下json响应:

{
 "data":
       {
        "plans":
          [
           {
             "planid":"10",
             "plandescription":"foo",
             "plantype":"2",
             "planvalue":"30",
             "status":"Active"
           }
         ]
       }
}

这就是我要做的事情:

RKObjectMapping *planMapping = [RKObjectMapping mappingForClass:[Plans class]];
[planMapping addAttributeMappingsFromDictionary:@{
 @"planid": @"planId",
 @"plandescription": @"planDescription",
 @"plantype": @"planType",
 @"planvalue": @"planValue",
 @"status" : @"status"
 }];

RKResponseDescriptor *planResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:planMapping pathPattern:nil keyPath:@"data/plans" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:planResponseDescriptor];

然而,对象没有被映射:\有什么问题?

1 个答案:

答案 0 :(得分:0)

尝试将keyPath:@“data / plans”更改为keyPath:@“data.plans”