我使用RestKit版本0.26并尝试将响应映射到核心数据
这是我用于构建请求和描述符的代码的代码:
-(void)getProductListProductWithPageNumber: (int) pageNumber managedObjectStore: (RKManagedObjectStore *)managedObjectStore {
// initialize AFNetworking HTTPClient
NSURL *baseURL = [NSURL URLWithString:@"https://server.com"];
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
objectManager.managedObjectStore = managedObjectStore;
RKResponseDescriptor *productListrResponseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:[[CategoricalSystemDownloadManager sharedDownloadManager] getCDProductListProductMapping:managedObjectStore]
method:RKRequestMethodGET
pathPattern:@"/PLController/plProducts/:"
keyPath:nil
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:productListrResponseDescriptor];
[objectManager getObjectsAtPath:[NSString stringWithFormat:@"/PLController/plProducts/currentResponseBody-%d", pageNumber]
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];
}
映射的JSON确实是一个数组 - >关键路径为零,对吗? 它看起来像这样: [ { " productId":240, " brandId":69 } ]
这是错误
which failed to match all (0) response descriptors
答案 0 :(得分:0)
我弄乱了pathPattern。它应该是/ PLController / plProducts /:currentResponseBody