2

对于以下 XML,我有一个非常简单的 RestKit 映射:

<category name="religious">
  <book isbn="42">HHGTTG</book>
  <book isbn="7">The bible</book>
</category>

现在解析这个时,我得到一个category包含两个对象的book对象。现在在我的书对象中,我想参考category.

这似乎是一件很容易实现的事情,但我在Object Mapping Documentation中没有找到任何内容。

更新:这是我的映射的样子:

RKObjectMapping *bookMapping = [RKObjectMapping mappingForClass:[Book class]];
[bookMapping mapKeyPath:@"isbn" toAttribute:@"isbn"];

RKObjectMapping* categoryMapping = [RKObjectMapping mappingForClass:[Category class]];
[categoryMapping mapKeyPath:@"name" toAttribute:@"name"];
// Relationship to book
[categoryMapping mapKeyPath:@"book" toRelationship:@"books" withMapping:bookMapping];
4

0 回答 0