使用Restkit iphone进行映射
我试图使用restkit对象映射来映射和存储响应json数据。不幸的是,我无法映射响应数据。当我查看我的数据库时,数据正在存储,但我收到一个崩溃消息,消息如下。。 此类不符合密钥的键值编码要求 输出响应使用Restkit iphone进行映射,iphone,objective-c,xcode,mapping,restkit,Iphone,Objective C,Xcode,Mapping,Restkit,我试图使用restkit对象映射来映射和存储响应json数据。不幸的是,我无法映射响应数据。当我查看我的数据库时,数据正在存储,但我收到一个崩溃消息,消息如下。。 此类不符合密钥的键值编码要求 输出响应 { "users": [ { "id": "123456", "ne": "JohnSmith", "el": "example@example.com", "dob": "1
{
"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)中,我遇到了崩溃,但配置文件的详细信息插入到了数据库中。当我将keypath更改为profile时,我不会得到任何崩溃,但配置文件详细信息不会插入数据库中
[userProfileMapping mapRelationship:@"users" withMapping:standardProfileMapping];
错误消息:
*由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合密钥配置文件的键值编码要求。”这是因为您的
用户
参数是一个NSArray,而不是NSDictionary。它不知道要使用哪个用户.profile
您要更改同一行:
[manager.mappingProvider setMapping:standardProfileMapping forKeyPath:@"users.profile"];
致:
并将此行添加到userProfileMapping:
[userProfileMapping mapKeyPath: @"profile" toRelationship: @"profile" withMapping: standardProfileMapping]
这是因为
users
参数是NSArray,而不是NSDictionary。它不知道要使用哪个用户.profile
您要更改同一行:
[manager.mappingProvider setMapping:standardProfileMapping forKeyPath:@"users.profile"];
致:
并将此行添加到userProfileMapping:
[userProfileMapping mapKeyPath: @"profile" toRelationship: @"profile" withMapping: standardProfileMapping]
谢谢你的回复。实际上,我希望数组中的所有数据都存储在db中。我已经试过最后一个代码了。但是配置文件数据没有插入到数据库中。只有用户数据存储在ur响应的X中。实际上,我希望数组中的所有数据都存储在db中。我已经试过最后一个代码了。但是配置文件数据没有插入到数据库中。只有用户在存储数据