2013-05-30 102 views
0

我想从Foursquare(FS)调用映射结果。当我使用AFNetworking时,它按预期返回FS结果(JSON)。当我用RKEntityMapping或RKObjectMapping尝试与Restkit的调用时,出现以下错误。Restkit给映射错误:

RKMapperOperation.m:98添加映射错误:发现任何属性或关系映射

任何建议的任何可映射值?我错过了什么吗?我知道我没有关于一些位置信息的关系映射设置,但我似乎无法将它映射到顶层的东西。

RESTKIT ===============

// --- VENUE MAPPING ------------------------------ 

RKEntityMapping *venueMapping = [RKEntityMapping mappingForEntityForName:@"Venue" 
                inManagedObjectStore:objectManager.managedObjectStore]; 

[venueMapping addAttributeMappingsFromArray:@[@"name"] ]; 

[venueMapping addAttributeMappingsFromDictionary:@{ 
@"id": @"venueID" 
}]; 


[venueMapping setIdentificationAttributes:@[@"venueID"] ]; 



// Routes for Users 
[self.foursquareManager.router.routeSet addRoute:[RKRoute routeWithClass:[Venue class] 
                pathPattern:@"v2/venues/search" 
                 method:RKRequestMethodGET]]; 


// Register our mappings with the provider 
RKResponseDescriptor *venueResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:venueMapping 
                         pathPattern:@"v2/venues/search" 
                          keyPath:nil 
                         statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

RKResponseDescriptor *venueDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:venueMapping 
                       pathPattern:@"v2/venues/search" 
                        keyPath:nil 
                       statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 


[self.foursquareManager addResponseDescriptor:venueResponseDescriptor]; 
[self.foursquareManager addResponseDescriptor:venueDescriptor]; 

[self.foursquareManager getObject:nil 
             path:@"v2/venues/search" 
           parameters:@{ 
              @"client_id" : kFourSquareClientID, 
              @"client_secret" : kFourSquareClientSecret, 
              @"ll" : searchString, 
              @"v" : @"20130101" 
              } 

            success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { 

             DLog(@"Getting favorites return successful update tableview and CD "); 


            } 
            failure:^(RKObjectRequestOperation *operation, NSError *error) { 
             DLog(@"Getting all favorites failed: %@", [error localizedDescription]); 

            }]; 

AFNETWORKING =============

如果我使用自动对焦进行使它的调用完美返回JSON数据。

NSString *searchString = [NSString stringWithFormat:@"%@, %@",[dictionary objectForKey:@"lat"], [dictionary objectForKey:@"lng"]]; 
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"https://api.foursquare.com"]]; 


NSDictionary *parameters = @{ 
          @"client_id" : kFourSquareClientID, 
          @"client_secret" : kFourSquareClientSecret, 
          @"ll" : searchString, 
          @"v" : @"20130101" 
          }; 

NSMutableURLRequest *request = [client requestWithMethod:@"GET" path:@"/v2/venues/search" parameters:parameters]; 
DLog(@""); 
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 


    NSError *error; 
    NSDictionary* json = [NSJSONSerialization 
          JSONObjectWithData:JSON //1 
          options:kNilOptions 
          error:&error]; 

    NSLog(@"THIS IS A DICTIONARY (or array): %@", JSON); 

} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { 
    NSLog(@"if requestFailed"); 
}]; 

[operation start]; 

MY场馆对象==========

@interface Venue : NSManagedObject 

@property (nonatomic, retain) NSString * venueID; 
@property (nonatomic, retain) NSString * name; 
@property (nonatomic, retain) NSString * address; 
@property (nonatomic, retain) NSNumber * verified; 

@end 

回答

0

发现的问题。这将解决它。

keyPath:@"response.venues" 

FourSquare返回的JSON有许多属性和子数组信息。 keyPath是您需要走到JSON数据“场地”的路径。如果您需要到达返回的“位置”信息,则可以使用以下keyPath(遍历层次结构)。

keyPath:@"response.venues.location" 
+0

你能解释一下为什么它会解决它吗? –