0

我有一个 web 服务返回一个 JSON 格式的字符串,如下所示:

{"id":4,
 "name":"name",
 "image":1,
 "contacts":[2,3]
}

联系人数组包含其他对象的主键的位置。我尝试以这种方式进行映射:

RKManagedObjectMapping* mapping = [RKManagedObjectMapping mappingForClass:[OETGroup class] inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
[mapping mapKeyPath:@"id" toAttribute:@"identifiant"];
[mapping mapKeyPath:@"name" toAttribute:@"name"];
[mapping mapKeyPath:@"image" toAttribute:@"image"];
RKManagedObjectMapping* contactSimpleMapping = [RKManagedObjectMapping mappingForClass:[OETContact class] inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
[contactSimpleMapping mapKeyPath:@"" toAttribute:@"identifiant"];

[mapping mapKeyPath:@"contacts" toRelationship:@"contacts" withMapping:contactSimpleMapping];
[mapping connectRelationship:@"contacts" withObjectForPrimaryKeyAttribute:@"contacts"];

[mapping setPrimaryKeyAttribute:@"identifiant"];

但是每次我运行这段代码时,我都会遇到这个异常:

this class is not key value coding-compliant for the key .'

知道为什么吗?

4

0 回答 0