iOS Restkit:如何解析嵌套路径

时间:2014-02-26 18:13:38

标签: ios objective-c json restkit

我有这种类型的JSON响应:

{
"d": { "id": "1", "user": "test"}
}

我使用以下代码解析Restkit:

@interface ODataUser : NSObject<ODataObject>

@property (nonatomic, copy) NSString * id;
@property (nonatomic, copy) NSString * user;

-(NSString*)getId;
-(NSString*)getUser;
@end
  

RKObjectMapping * map = [RKObjectMapping mappingForClass:[ODataUser   类]]; [mapping addAttributeMappingsFromDictionary:@ {@“id”:   @“id”,@“user”:@“user”}];

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:map method:RKRequestMethodGET  pathPattern:nil keyPath:@"d" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

但是,现在我的回复已经改为:

{
"d": { "results": [ {"id": "1", "user": "test"} ] }
}

如何在代码上反映这些更改?

1 个答案:

答案 0 :(得分:0)

更改您的响应描述符以使用:

keyPath:@"d.results"

因为这将导航到d字典以获取results数组并处理它包含的所有字典。