RestKit映射:一次映射不同的对象

时间:2012-06-30 05:40:02

标签: ios rest networking restkit

我有一个像这样的JSON

{
  "result" : 1,
  "messages" : [],
  "users" : {}
}

填充messagesusers

如果我要映射,例如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

1 个答案:

答案 0 :(得分:2)

以类似的方式创建映射并设置:

[messageManager.mappingProvider setMapping: userMapping forKeyPath:@"users"];