我已经浏览了包括https://github.com/RestKit/RestKit/wiki/Object-mapping在内的可用文档,但我无法找到将 GET 结果映射到的解释或示例
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects
(NSArray*)objects 到底是什么?
当我从服务器只返回一个 JSON 对象时,我能够将其映射为:
NSString *bodyResults;
bodyResults = [[objectLoader response] bodyAsString];
NSDictionary *resultsDictionary = [bodyResults objectFromJSONString];
NSString *subject = [resultsDictionary objectForKey:@"subject"];
但是现在我要返回一个 JSON 列表(一组对象),我遇到了麻烦。
我在提交获取之前映射了对象:
//地图提供 RKObjectMapping* OfferingMapping = [RKObjectMapping mappingForClass:[Offering class]]; [offeringMapping mapKeyPath:@"categoryId" toAttribute:@"categoryId"]; [offeringMapping mapKeyPath:@"merchantId" toAttribute:@"merchantId"]; [offeringMapping mapKeyPath:@"name" toAttribute:@"name"]; [offeringMapping mapKeyPath:@"latitude" toAttribute:@"latitude"]; [offeringMapping 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];
谢谢