ios – 错误:’无法为keyPath新闻添加映射,一个已经存在…’

ios – 错误:’无法为keyPath新闻添加映射,一个已经存在…’,第1张

概述我正在使用RestKit从Restful Web Service获取数据.使用平面文件,它可以很好地工作.如果我想获得嵌套 JSON的响应,我的问题就开始了. 我的JSON看起来像: [{"homename":"Alien","created_at":"2011-09-15T12:46:37Z", "updated_at":"2011-09-15T12:46:37Z","gametype":"Fi 我正在使用RestKit从Restful Web Service获取数据.使用平面文件,它可以很好地工作.如果我想获得嵌套 JSON的响应,我的问题就开始了.

我的JsON看起来像:

[{"homename":"AlIEn","created_at":"2011-09-15T12:46:37Z","updated_at":"2011-09-15T12:46:37Z","gametype":"Final match","ID":1,"date":"2016-10-10","guestname":"Predator","news":[{"minute":null,"created_at":"2011-09-15T13:19:51Z","player":null,"Title":"Title","updated_at":"2011-09-15T13:19:51Z","bodytext":"News","game_ID":1},{"minute":null,"created_at":"2011-09-15T13:22:06Z","Title":"New news","updated_at":"2011-09-15T13:22:06Z","ID":2,"bodytext":"old socks","created_at":"2011-09-15T13:26:32Z","Title":"another Title","updated_at":"2011-09-15T13:26:32Z","ID":3,"bodytext":"Bodytext 2","created_at":"2011-09-22T12:35:19Z","Title":"comment","updated_at":"2011-09-22T12:35:19Z","ID":4,"bodytext":"body of the comment","game_ID":1}]}]

使用以下代码,我想获取映射的数据.

RKLogConfigureByname("RestKit/Network*",RKLogLevelTrace);// Initialize RestKitRKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://X.X.X.X:3000"];// Enable automatic network activity indicator management//objectManager.clIEnt.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;RKObjectMapPing* newsMapPing = [RKObjectMapPing mapPingForClass:[News class]];[newsMapPing mapKeyPath:@"ID" toAttribute:@"ID"];[newsMapPing mapKeyPath:@"minute" toAttribute:@"minute"];[newsMapPing mapKeyPath:@"Title" toAttribute:@"Title"];[newsMapPing mapKeyPath:@"bodytext" toAttribute:@"bodytext"];// Setup our object mapPingsRKObjectMapPing* gameMapPing = [RKObjectMapPing mapPingForClass:[Game class]];//  [gameMapPing mapKeyPath:@"ID" toAttribute:@"ID"];[gameMapPing mapKeyPath:@"guestname" toAttribute:@"guestname"];[gameMapPing mapKeyPath:@"homename" toAttribute:@"homename"];[gameMapPing mapKeyPath:@"date" toAttribute:@"date"];[gameMapPing mapKeyPath:@"gametype" toAttribute:@"gametype"];[gameMapPing mapKeyPath:@"news" toAttribute:@"news"];[gameMapPing mapKeyPath:@"news" toRelationship:@"news" withMapPing:newsMapPing];[objectManager.mapPingProvIDer setMapPing:gameMapPing forKeyPath:@"games"];

该声明
[gameMapPing mapKeyPath:@“news”toRelationship:@“news”withMapPing:newsMapPing];
在运行时引发异常,我无法弄清楚原因:

*** Terminating app due to uncaught exception 'NSInternalinconsistencyException',reason: 'Unable to add mapPing for keyPath news,one already exists...'

有人看到我做错了吗? 1:n关系的关系是否错误

解决方法 新闻keyPath有两个映射:
[gameMapPing mapKeyPath:@"news" toAttribute:@"news"];

[gameMapPing mapKeyPath:@"news" toRelationship:@"news" withMapPing:newsMapPing];

删除第一个,看看它是否有帮助.

干杯.

总结

以上是内存溢出为你收集整理的ios – 错误:’无法为keyPath新闻添加映射,一个已经存在…’全部内容,希望文章能够帮你解决ios – 错误:’无法为keyPath新闻添加映射,一个已经存在…’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100658.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存