我无法将 JSON 映射到我的实体。错误消息是:添加映射错误:找不到 keyPath 的对象映射:''。我正在使用以下代码:
RKObjectMapping *lEgmMapping = [RKObjectMapping mappingForClass:[EGM
class]];
[lEgmMapping mapKeyPath:@"Id" toAttribute:@"Id"];
[lEgmMapping mapKeyPath:@"InternalId" toAttribute:@"internalId"];
[lEgmMapping mapKeyPath:@"PlayerType" toAttribute:@"playerType"];
[lEgmMapping mapKeyPath:@"PositionX" toAttribute:@"x"];
[lEgmMapping mapKeyPath:@"PositionY" toAttribute:@"y"];
[lEgmMapping mapKeyPath:@"Size" toAttribute:@"size"];
[lEgmMapping mapKeyPath:@"Status" toAttribute:@"status"];
[[RKObjectManager sharedManager].mappingProvider
setMapping:lEgmMapping forKeyPath:@"GetEgmMarkersBySiteResult"];
我正在从 Web 服务获取以下 JSON:
{"GetEgmMarkersBySiteResult":[{"Id":
94,"InternalId":"A2345","PlayerType":"2","PositionX":686,"PositionY":
1460,"Size":23,"Status":"0"},{"Id":
83,"InternalId":"A1002a","PlayerType":"0","PositionX":1414,"PositionY":
906,"Size":30,"Status":"0"},{"Id":
81,"InternalId":"asd","PlayerType":"0","PositionX":1338,"PositionY":
925,"Size":33,"Status":"0"}]}
我究竟做错了什么?谢谢你。
编辑:事实证明,当它在 appdelegate applicationlaunchedwithoptions 上时找不到映射,我认为这是加载绑定的好地方。您认为哪里是加载绑定的好地方?如果另一个视图控制器定义了相同的绑定,它会导致运行时错误吗?