Ios RestKit警告-警告:映射嵌套对象失败:(null)
我刚开始学习RestKit。我正在尝试使用Foursquare API获取附近的场馆。但每次我尝试“objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)对象”时,我都会收到以下警告:“警告:映射嵌套对象失败:(null)” 我真的很困惑。以下是我在init方法中的映射代码:Ios RestKit警告-警告:映射嵌套对象失败:(null),ios,ios5,warnings,restkit,Ios,Ios5,Warnings,Restkit,我刚开始学习RestKit。我正在尝试使用Foursquare API获取附近的场馆。但每次我尝试“objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)对象”时,我都会收到以下警告:“警告:映射嵌套对象失败:(null)” 我真的很困惑。以下是我在init方法中的映射代码: _objectManager = [RKObjectManager objectManagerWithBaseURL:@"https://
_objectManager = [RKObjectManager objectManagerWithBaseURL:@"https://api.foursquare.com"];
RKObjectMapping *locationMapping = [RKObjectMapping mappingForClass:[Location class]];
[locationMapping mapKeyPath:@"address" toAttribute:@"address"];
[locationMapping mapKeyPath:@"city" toAttribute:@"city"];
[locationMapping mapKeyPath:@"state" toAttribute:@"state"];
[_objectManager.mappingProvider setMapping:locationMapping forKeyPath:@"location"];
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Groups class]];
[venueMapping mapRelationship:@"location" withMapping:locationMapping];
[_objectManager.mappingProvider setMapping:venueMapping forKeyPath:@"groups"];
RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[Response class]];
[responseMapping mapRelationship:@"groups" withMapping:venueMapping];
[_objectManager.mappingProvider setMapping:responseMapping forKeyPath:@"response"];
return self;
以下是“locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation”中的代码
最后,这段代码出现在“objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)对象”中
以下是我在控制台中得到的响应:
2012-02-26 13:15:39.872 restKitPractice[8609:690b]W restkit对象映射:RKObjectMappingOperation.m:372警告:映射嵌套对象失败:(null)
我收到的对象是(
“响应:0x6b5cb20”
)
您可以使用以下链接从Foursquare检查场地json:
任何帮助或建议将不胜感激,因为我真的在与这个问题斗争
谢谢
Vik你应该看一下
您的映射定义与您试图解析的json不匹配 我意识到这是一个老问题,但我也看到了同样的警告。原因是您有这样的JSON
{“response”:{}}
要映射到一个对象。由于对象中没有键,因此它基本上映射为nil
。所以,这个警告是无害的。您将无法返回响应
对象,因为服务器实际上返回了RestKit无法映射的内容,因为JSON中没有与任何属性映射匹配的键。RestKit让您知道这一点,并警告您不要创建对象
NSString *resourceURLString = [NSString stringWithFormat:@"/v2/venues/search?ll=%f,%f&limit=10&client_id=LEA1MYN1Z1QWSBFIOA1T4FREVVNF0R1ADQKMA0AMGL3CN5N4&client_secret=M2W204MKEAO4KV5L4ZXUYWK2GC32PO0KT5PWYJQBP4FKBTMO",newLocation.coordinate.latitude, newLocation.coordinate.longitude];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:resourceURLString delegate:self];
[_locationManager stopUpdatingLocation];
_objects = [objects retain];
NSLog(@"object that i receive is %@",objects);