我已阅读了包含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:
之前映射了对象//地图提供 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];
由于
答案 0 :(得分:0)
在回答第一个问题时,(NSArray *)对象是objectLoader加载的对象数组。因此,在您的情况下,它们应该是类型为对象的对象,其中填充了您在对象映射中映射的属性。
您是否有可以在此处发布的GET请求中返回的JSON示例?你确定它是有效的JSON并且正如你预期的那样被返回吗?