响应映射以获取带有动态路径Restkit的对象 [英] Response mapping to get object with dynamic path restkit
问题描述
如果路径上的getobjects与用于映射响应的路径模式不同,如何将响应映射设置为具有路径模式的管理器.
how to i set response mapping to manager with path pattern ..if the getobjects at path is different from path pattern that is used to map the response.
[manager addResponseDescriptorsFromArray:
@[[RKResponseDescriptor responseDescriptorWithMapping:categoryMapping
pathPattern:A
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]]];
[manager getObjectsAtPath:A/ID
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@" Category success");
[self.delegate didReceiveAssignedCategories];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Category failure");
}];
响应映射路径ie:A必须设置为用于获取对象的动态路径ie:A/ID. 例如:
response mapping path ie:A must be set to dynamic path used to getobject ie:A/ID . ex:
致电1)
A =/getAllCategories
A = /getAllCategories
A/ID =/getAllCategories/123
A/ID = /getAllCategories/123
致电2)
A =/getAllCategories
A = /getAllCategories
A/ID =/getAllCategories/456
A/ID = /getAllCategories/456
123、456的响应映射相同 仅在获取对象时,我使用的是不同的网址,即:带有ID的附件. 该怎么做?
response mapping is same for 123, 456 only while getting the objects i am using different urls ie: with id's attached. how to do that ?
推荐答案
如果您有两个路径模式均返回相同类型的数据,则可以将相同的映射与2个不同的响应描述符一起使用.
If you have 2 path patters which both return the same type of data then you can use the same mapping with 2 different response descriptors.
如果您有一种路径模式可以返回2种不同类型的数据,则需要使用RKDynamicMapping
来拦截"传入的数据并确定实际需要的映射.
If you have 1 path pattern which can return 2 different types of data then you need to use RKDynamicMapping
to 'intercept' the incoming data and decide which mapping is actually required.
根据您编辑过的问题,模式"是您误解的重要内容.您需要使用路径模式,而不是静态路径:
From your edited question, 'pattern' is the important thing that you have misunderstood. You need to use a path pattern, not a static path:
@"getAllCategories/:identity"
这篇关于响应映射以获取带有动态路径Restkit的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!