2012-02-26 69 views
1

我剛開始學習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:

https://api.foursquare.com/v2/venues/search?ll=40.562362,-111.938689&limit=10&client_id=LEA1MYN1Z1QWSBFIOA1T4FREVVNF0R1ADQKMA0AMGL3CN5N4&client_secret=M2W204MKEAO4KV5L4ZXUYWK2GC32PO0KT5PWYJQBP4FKBTMO

不限我會感激你的幫助或建議,因爲我是真實的我正在努力解決這個問題。

感謝 維克

回答

0

我意識到這是一個老問題,但我看到了同樣的警告。原因是你有JSON像這樣{"response":{}},你想映射到一個對象。由於對象中沒有鍵,所以它基本上映射到nil。所以,這個警告是非常無害的。您不會收到Response對象,因爲服務器基本上返回了RestKit無法映射的內容,因爲JSON中沒有與您的任何屬性映射匹配的鍵。 RestKit讓你知道這個警告並且回落到不創建一個對象。