1

Foursquare API から最寄りのレストランに関する情報を取得するためにこのコードを書きますが、モデルに基づいて会場の ID と名前を取得するのに問題があります。 :

W restkit.object_mapping:RKObjectMappingOperation.m:244 keyPath 'id' で値の変換に失敗しました。「__NSArrayI」から「NSString」への変換方法がない

問題を解決するのに役立つ何かを見つけたいですか?

- (void)viewDidLoad
{
    [super viewDidLoad];
    /* need to change base on our API */
    RKURL *baseUrl = [RKURL URLWithBaseURLString:@"https://api.Foursquare.com/v2"];

    RKObjectManager *objectManager = [RKObjectManager objectManagerWithBaseURL:baseUrl];
    objectManager.client.baseURL = baseUrl;

    /* solve the problem tomorrow inshaallah */
    RKObjectMapping *resturantMapping = [RKObjectMapping mappingForClass:[Resturant class]];
    [resturantMapping mapKeyPathsToAttributes:@"id",@"ID",@"name",@"name", nil];
    resturantMapping.rootKeyPath = @"venue"; 
    [objectManager.mappingProvider setMapping:resturantMapping forKeyPath:@"response.groups.items.veue"];

    RKObjectMapping *locationMapping = [RKObjectMapping mappingForClass:[Location class]];
    [locationMapping mapKeyPathsToAttributes:@"address", @"address", @"city", @"city", @"country", @"country", @"crossStreet", @"crossStreet", @"postalCode", @"postalCode", @"state", @"state", @"distance", @"distance", @"lat", @"lat", @"lng", @"lng", nil];

    [resturantMapping mapRelationship:@"location" withMapping:locationMapping];
    [objectManager.mappingProvider setMapping:locationMapping forKeyPath:@"location"];

 [self sendRequest]; 
}


-(void)sendRequest {


    NSString *latLon = [NSString stringWithFormat:@"%g,%g",self.userCurrentLocation.coordinate.latitude,self.userCurrentLocation.coordinate.longitude];
    NSString *clientID = CLIENT_ID;
    NSString *clientSecret = CLIENT_SECRET;


    NSDictionary *queryParams;
    queryParams = [NSDictionary dictionaryWithObjectsAndKeys:latLon, @"ll", clientID, @"client_id", clientSecret, @"client_secret", @"food", @"section", @"50", @"limit", nil];
    RKObjectManager *objectManager = [RKObjectManager sharedManager];

    RKURL *URL = [RKURL URLWithBaseURL:[objectManager baseURL] resourcePath:@"/venues/explore" queryParameters:queryParams];
    [objectManager loadObjectsAtResourcePath:[NSString stringWithFormat:@"%@?%@", [URL resourcePath], [URL query]] delegate:self];

}
4

0 に答える 0