有人可以解释映射Restkit获取结果映射到数组
我已经通过可用的文档,包括https://github.com/RestKit/RestKit/wiki/Object-mapping,我一直无法找到解释或示例来映射GET结果
究竟是什么(NSArray *)对象?
当我从服务器返回一个JSON对象时,我可以将它映射到:
NSString *bodyResults;
bodyResults = [[objectLoader response] bodyAsString];
NSDictionary *resultsDictionary = [bodyResults objectFromJSONString];
NSString *subject = [resultsDictionary objectForKey:@"subject"];
但是现在,我返回一个JSON列表(选择的对象),我遇到了麻烦。
我在提交get之前映射对象:
// map提供RKObjectMapping * offeringMapping = [RKObjectMapping mappingForClass:[Offering class]]; [offeringMapping mapKeyPath:@“categoryId”toAttribute:@“categoryId”]; [提供映射关键字路径:@“merchantId”toAttribute:@“merchantId”]; [offeringMapping mapKeyPath:@“name”toAttribute:@“name”]; [offeringMapping mapKeyPath:@“latitude”toAttribute:@“latitude”]; [提供映射mapKeyPath:@“longitude”toAttribute:@“longitude”];
[[RKObjectManager sharedManager].mappingProvider setMapping:offeringMapping forKeyPath:@"offering"];
double latitude = [(AppDelegate*)[[UIApplication sharedApplication] delegate] currentLatitude];
double longitude = [(AppDelegate*)[[UIApplication sharedApplication] delegate] currentLongitude];
NSString *latitudeString = [[NSNumber numberWithDouble:latitude] stringValue];
NSString *longitudeString = [[NSNumber numberWithDouble:longitude] stringValue];
NSDictionary *getParams = [NSDictionary dictionaryWithKeysAndObjects:
@"lat",latitudeString,
@"long",longitudeString,
nil];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/merchantofferings" stringByAppendingQueryParameters:getParams] delegate:self];
谢谢
作为对第一个问题的回应,(NSArray *)对象是由objectLoader加载的对象的数组。 所以在你的情况下,它们应该是使用你在对象映射中映射的属性填充的类型的对象。
你有没有从GET请求返回的JSON样本,你可以在这里发布? 你确定它是有效的JSON并且完全按照你的预期返回吗?
链接地址: http://www.djcxy.com/p/49193.html上一篇: Can someone explain mapping Restkit Get results mapping into an Array
下一篇: Creating instance for NSManagedObject Class using Restkit