作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
日志:
2014-04-09 15:03:10.196 App[49808:60b] request <NSMutableURLRequest: 0xd091170> { URL: http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z }
2014-04-09 15:03:10.214 App[49808:60b] I restkit.network:RKObjectRequestOperation.m:180 GET 'http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z'
2014-04-09 15:03:10.300 App[49808:632f] D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: {
meetups = (
{
activities = (
{
activityId = 37;
activityType = "<null>";
customData = "<null>";
locationAddress = "k2-LocationAddress";
locationName = "k2-LocationName";
startTime = "0000-00-00 00:00:00";
},
{
activityId = 38;
activityType = "<null>";
customData = "<null>";
locationAddress = "k-LocationAddress";
locationName = "k-LocationName";
startTime = "0000-00-00 00:00:00";
}
);
comment = comment;
gettingBack = "gettingBack Test";
gettingThere = "gettingBack Test";
meetingType = 1;
meetupId = 65;
modified = "2014-04-09T20:59:29.000Z";
ownerId = Joe;
recipientId = "<null>";
}
);
}
and targetObject: (null)
2014-04-09 15:03:10.301 App[49808:632f] D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: (null)
2014-04-09 15:03:10.302 App[49808:21f] E restkit.network:RKObjectRequestOperation.m:243 GET 'http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z' (200 OK / 0 objects) [request=0.0849s mapping=0.0000s total=0.1043s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0xd0b5a40 {NSErrorFailingURLStringKey=http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://www.domain.com/meetups?lastrequest=2014-04-09T15%3A03%3A10Z, NSUnderlyingError=0xd08a190 "No mappable object representations were found at the key paths searched."}
代码:
@property (strong, nonatomic) RKObjectManager *objectManager;
....
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.objectManager = [self getObjectManager];
self.objectManager.managedObjectStore = [appDelegate setupCoreDataWithRESTKit];
[RKObjectManager sharedManager].requestSerializationMIMEType = RKMIMETypeJSON;
RKEntityMapping *invitationMapping = [RKEntityMapping mappingForEntityForName:@"Invite" inManagedObjectStore:self.objectManager.managedObjectStore];
[invitationMapping addAttributeMappingsFromDictionary:@{
@"recipientId" : @"recipientId",
@"meetingType" : @"meetingType",
@"startDate" : @"startDate",
@"gettingThere" : @"gettingThere",
@"gettingBack" : @"gettingBack",
@"comment" : @"comment"
}];
invitationMapping.identificationAttributes = @[@"meetupId"];
RKEntityMapping *activityMapping = [RKEntityMapping mappingForEntityForName:@"Activity" inManagedObjectStore:self.objectManager.managedObjectStore];
[activityMapping addAttributeMappingsFromDictionary:@{
@"locationName" : @"locationName",
@"locationAddress" : @"locationAddress",
@"startTime" : @"startTime",
@"customData" : @"customData"
}];
activityMapping.identificationAttributes = @[@"activityId"];
NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
[invitationMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"activities" toKeyPath:@"activities" withMapping:activityMapping]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:invitationMapping
method:RKRequestMethodGET
pathPattern:@"/meetups"
keyPath:@"meetups" statusCodes:statusCodeSet];
NSMutableURLRequest *request = [self.objectManager.HTTPClient requestWithMethod:@"GET"
path:@"/meetups"
parameters:@{@"lastrequest": dateString
}];
[self.objectManager.HTTPClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc]initWithRequest:request responseDescriptors:@[responseDescriptor]];
operation = [self.objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:self.objectManager.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSArray *array = mappingResult.array;
NSLog(@"array %@", array);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];
[operation start];
}
Invite
与名为 activities
的 Activity
有一对多关系。
为什么我得到:“在搜索的关键路径上找不到可映射的对象表示。” ?
最佳答案
这是创建操作的正确方法:
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc]initWithRequest:request responseDescriptors:@[responseDescriptor]];
但随后您将那个替换为另一个创建的:
operation = [self.objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:self.objectManager.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
正确使用对象管理器。这个问题是你没有把响应描述符给对象管理器,你只把它给了刚刚销毁的操作(因为你替换了它)。
因此,使用您创建的第一个操作,并通过调用 setCompletionBlockWithSuccess:failure:
在其上设置成功和失败 block 。
关于ios7 - RESTKit:在搜索的关键路径中找不到可映射的对象表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22975062/
1.最小生成树:无向连通图的所有生成树中有一棵边的权值总和最小的生成树 1.1 问题背景: 假设要在n个城市之间建立通信联络网,则连通n个城市只需要n—1条线路。这时,自然会考虑这样一个问题,如何
我是一名优秀的程序员,十分优秀!