iOS 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 class]]; [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"} ] }
}
我如何才能在我的代码上反映这些更改?
更改您的回复描述符以使用:
keyPath:@"d.results"
因为这将导航到d
字典中以获取results
数组并处理其包含的所有字典。