2012-01-12 67 views
0

在此先感谢您的所有帮助社区!我有一个早期的问题,这是我指出的,我解决了“[人员对象] - 应该 - > [人员分配]初始化]我修复了,现在可以添加一个人对象,现在我的服务器。问题所有在服务器上的值都为空,并且返回1001代码Code = 1001“找不到KeyPath的对象映射:''”UserInfo = 0x5938ce0 {= RKObjectMapperKeyPath,NSLocalizedDescription =找不到KeyPath的对象映射: “”} 什么我映射不对任何想法?Noobie这里是所提供的任何帮助,不胜感激! 喔啊很愿意,如果你在南加州的支付经验在这个问题上,日Thnx了!RESTkit代码1001找不到keyPath对象:“'”

RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[Person class]]; 
[userMapping mapKeyPath:@"updated_at" toAttribute:@"updatedAt"]; 
[userMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"]; 
[userMapping mapKeyPath:@"name" toAttribute:@"name"]; 
[userMapping mapKeyPath:@"id" toAttribute:@"personId"]; 

RKObjectMapping* dogMapping = [RKObjectMapping mappingForClass:[Dog class]]; 
[dogMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"]; 
[dogMapping mapKeyPath:@"person_id" toAttribute:@"spersonId"]; 
[dogMapping mapKeyPath:@"name" toAttribute:@"name"]; 
[dogMapping mapKeyPath:@"updated_at" toAttribute:@"updatedAt"]; 
[dogMapping mapKeyPath:@"id" toAttribute:@"dogId"]; 

RKObjectMapping *dataMapping = [RKObjectMapping mappingForClass:[Data class]]; 
[dataMapping mapKeyPath:@"dog" toAttribute:@"dogs"]; 
[dataMapping mapKeyPath:@"person" toRelationship:@"person" withMapping:userMapping]; 
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:dataMapping]; 

[[RKObjectManager sharedManager].mappingProvider setMapping:userMapping 
forKeyPath:@"people"]; 

RKObjectRouter * router = [RKObjectManager sharedManager].router; 
[router routeClass: [Person class] toResourcePath:@"/people/:personId"]; 
[router routeClass: [Person class] toResourcePath:@"/people" 
forMethod:RKRequestMethodPOST]; 

RKObjectMapping *personSerializationMapping= [RKObjectMapping mappingForClass: 
[NSMutableDictionary class]]; 
[personSerializationMapping mapAttributes:@"name", nil]; 
[[RKObjectManager sharedManager].mappingProvider 
setSerializationMapping:personSerializationMapping forClass: [Person class]]; 

Person* daveLiu =[[[Person alloc]init]autorelease]; 
daveLiu.name = @"dave"; 
[[RKObjectManager sharedManager] postObject:daveLiu delegate:self]; 
+0

你想发布到服务器或从服务器读取? – chourobin 2012-03-14 10:12:35

回答

1

所有我的服务器中的对象是“匿名的”,并且我有与RestKit无法相同的问题找到正确的映射。我固定它的方式是使用的ObjectManager方法,让我有映射:所以现在

[objectManager postObject:object mapResponseWith:[object objectMapping] delegate:self]; 
[objectManager loadObjectsAtResourcePath:path objectMapping:mapping delegate:self]; 

我的合同,所有来自这样的服务器:

{ 
    "Id": "12345678-1234-1234-1234-1234567890ab", 
    "Type": "SURVEY", 
    "Code": "1234", 
    "Description": "blah blah blah", 
    "Message": "blah blah blah", 
    "Url": "http://nowhere.com/", 
    "NextAttemptHours": 4 
} 

可以映射到正确的对象。让对象映射可用,这是一项额外的工作,但它完成了这项工作。我通过在我的对象上实现一个类方法来做到这一点,以返回适当的objectMapping,它使事情变得非常干净和易于理解。