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