我有这种类型的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"} ] }
}
如何在代码上反映这些更改?
答案 0 :(得分:0)
更改您的响应描述符以使用:
keyPath:@"d.results"
因为这将导航到d
字典以获取results
数组并处理它包含的所有字典。