2

我有这样的 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

4

1 回答 1

2

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

[messageManager.mappingProvider setMapping: userMapping forKeyPath:@"users"];
于 2012-07-02T06:50:41.077 回答