iOS Restkit: how to parse nested path
I had a JSON response of this type:
{
"d": { "id": "1", "user": "test"}
}
which I was parsing with Restkit with the following code:
@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)];
However, now my response has changed to something like this:
{
"d": { "results": [ {"id": "1", "user": "test"} ] }
}
How can I reflect those changes on the response on my code?
Change your response descriptor to use:
keyPath:@"d.results"
as this will navigate into the d
dictionary to get the results
array and process all of the dictionaries it contains.
上一篇: 没有响应描述符匹配加载的响应
下一篇: iOS Restkit:如何解析嵌套路径