我有一个像这样的JSON
{
"result" : 1,
"messages" : [],
"users" : {}
}
填充messages
和users
。
如果我要映射,例如messages
,我会执行以下操作:
messageMapping = [RKObjectMapping mappingForClass:[OLMessage class]];
[messageMapping mapKeyPath:@"user_id" toAttribute:@"userID"];
[messageMapping mapKeyPath:@"status" toAttribute:@"status"];
[messageMapping mapKeyPath:@"text" toAttribute:@"text"];
[messageMapping mapKeyPath:@"date_time" toAttribute:@"date_time"];
messageManager = [RKObjectManager managerWithBaseURLString:baseURL];
[messageManager.mappingProvider setMapping:messageMapping forKeyPath:@"messages"];
[messageManager loadObjectsAtResourcePath:@"/messages/fetch" usingBlock:^(RKObjectLoader *loader) { ... };
我收到了我的消息。
如何设置我的映射以通过users
的相同呼叫获取loadObjectsAtResourcePath
?
答案 0 :(得分:2)
以类似的方式创建映射并设置:
[messageManager.mappingProvider setMapping: userMapping forKeyPath:@"users"];