尝试使用Reskit库但仍然有一些错误

时间:2012-11-25 17:14:01

标签: iphone ios

我写这个代码是为了从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];

}

0 个答案:

没有答案