我剛開始學習RestKit。我正在嘗試使用它來使用Foursquare API附近的場地。但每次我嘗試「objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)對象」我得到此警告「警告:映射嵌套對象失敗:(null)」。RestKit Warning - 警告:映射嵌套對象失敗:(null)
我真的很困惑。以下是我的映射代碼是在init方法:
_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 *)經理didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation」
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];
最後這段代碼是 「objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray的*)對象」
_objects = [objects retain];
NSLog(@"object that i receive is %@",objects);
以下是響應我得到我Ñ控制檯:
2012-02-26 13:15:39.872 restKitPractice [8609:690B]W¯¯restkit.object_mapping:RKObjectMappingOperation.m:372警告:未能映射嵌套對象:(空) 2012-02-26 13 :15:39.873 restKitPractice [8609:207]對象,我接收是( 「響應:0x6b5cb20」 )
可以從四方使用該鏈路檢查場地JSON:
不限我會感激你的幫助或建議,因爲我是真實的我正在努力解決這個問題。
感謝 維克