利用
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:myObject];
您应该检查Restkit Object Mapping Docs 上的“ Mapping without KVC ”部分。
这是文档中的一个示例:
[
{ "title": "RestKit Object Mapping Intro",
"body": "This article details how to use RestKit object mapping...",
"author": {
"name": "Blake Watters",
"email": "blake@restkit.org"
},
"publication_date": "7/4/2011"
}
]
你像这样映射:
// Our familiar articlesMapping from earlier
RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[Article class]];
[articleMapping mapKeyPath:@"title" toAttribute:@"title"];
[articleMapping mapKeyPath:@"body" toAttribute:@"body"];
[articleMapping mapKeyPath:@"author" toAttribute:@"author"];
[articleMapping mapKeyPath:@"publication_date" toAttribute:@"publicationDate"];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:articleMapping];