我正在尝试使用 restkit 对象映射来映射和存储响应 json 数据。不幸的是,我无法映射响应数据。当我查看我的数据库时,数据正在存储,但我收到以下消息时崩溃.. 这个类与键的键值编码不兼容
输出响应
{
"users": [
{
"id": "123456",
"ne": "JohnSmith",
"el": "example@example.com",
"dob": "1985/02/04",
"profile": {
"id": "654321",
"ht": "170cm",
"wt": "70kg"
}
}
]
}
我正在使用这样的映射
RKManagedObjectMapping *userProfileMapping = [RKManagedObjectMapping mappingForClass:[GHSUser class] inManagedObjectStore:manager.objectStore];
[userProfileMapping mapKeyPath:@"id" toAttribute:@"userId"];
[userProfileMapping mapKeyPath:@"ne" toAttribute:@"name"];
[userProfileMapping mapKeyPath:@"el" toAttribute:@"email"];
[userProfileMapping mapKeyPath:@"dob" toAttribute:@"dob"];
RKManagedObjectMapping *standardProfileMapping = [RKManagedObjectMapping mappingForClass:[GHSProfile class] inManagedObjectStore:manager.objectStore];
[standardProfileMapping mapKeyPath:@"id" toAttribute:@"userId"];
[standardProfileMapping mapKeyPath:@"ht" toAttribute:@"height"];
[standardProfileMapping mapKeyPath:@"wt" toAttribute:@"weight"];
[manager.mappingProvider setMapping:standardProfileMapping forKeyPath:@"users.profile"];
//在keypath(users.profile)中我遇到了崩溃,但配置文件详细信息正在插入数据库中。当我将密钥路径更改为配置文件时,我没有遇到任何崩溃,但配置文件详细信息未插入到数据库中。
[userProfileMapping mapRelationship:@"users" withMapping:standardProfileMapping];
错误信息:
* 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<_NSObjectID_48_2 0x888a8d0> setValue:forUndefinedKey:]:此类不符合密钥配置文件的密钥值编码。”