RestKit RKDynamicObjectMapping work only for first JSON result

痴心易碎 提交于 2019-12-12 03:08:24

问题


i got into an issue with RKDynamicObjectMapping, however it could be that i misuse it.

I have the following scenario

  1. request to the service to get areas
  2. choose area
  3. request to the service to get journals for selected area

data returned by both calls looks like that

{ d: [{cutID:""}, {cutID:""}, {cutID:""}] } 
{ d: [{journalID:""}, {journalID:""}, {journalID:""}] } 

i have the following code

RKObjectMapping* cutMapping = [RKObjectMapping mappingForClass:[Cut 
class]]; 
[cutMapping mapKeyPath:@"CutID" toAttribute:@"cutID"]; 
RKObjectMapping* journalMapping = [RKObjectMapping mappingForClass: 
[Journal class]]; 
[journalMapping mapKeyPath:@"journalID" toAttribute:@"journalID"]; 
RKDynamicObjectMapping * dynamicMapping  = [RKDynamicObjectMapping 
dynamicMapping]; 
[dynamicMapping setObjectMapping:journalMapping 
whenValueOfKeyPath:@"__metadata.type" isEqualTo:@"JournalDetails"]; 
[dynamicMapping setObjectMapping:cutMapping 
whenValueOfKeyPath:@"__metadata.type" isEqualTo:@"Cut"]; 
[[[RKObjectManager sharedManager] mappingProvider] 
setMapping:dynamicMapping forKeyPath:@"d"]; 

.... 

[objectManager loadObjectsAtResourcePath:getResourcePath 
delegate:self]; 

.... 

and later

[objectManager loadObjectsAtResourcePath:getResourcePath 
delegate:obj]; 

results of first request, which returns Cut objects, is mapped flawlessly, but not for second which returns Journal objects. logging in request:didLoadResponse showed that service returns expected json , so the issue is with mappings how to make it work with two mappings ?

Anyone using RestKit Dynamic Mapping yet ?


回答1:


I presume you've checked that your Cut object is mapping to a to-many relationship in the CoreData entity?

If so can you turn on the RESTKit logging and post the results



来源:https://stackoverflow.com/questions/8942696/restkit-rkdynamicobjectmapping-work-only-for-first-json-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!