如何通过restkit从api获取数据

时间:2014-03-12 18:02:27

标签: ios restkit-0.20

我从restkit开始,并有一个简单的帖子发送到api:

http://myapi.com/api/stats

发布参数:format=json

api回归:

{"cache_count":121,"user_count":322,"apps_count":1,"apps_active":47}

你能给我一个例子,说明如何在我的案例中使用restkit吗?

编辑:

我试过了:

NSURL *url = [[NSURL alloc] initWithString:@"http://myapi.com"];
    RKObjectManager *manager = [RKObjectManager managerWithBaseURL:url];
    NSDictionary *tmp = @{@"format": @"json"};

    [manager postObject:tmp path:@"/okapi/services/apisrv/stats" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
            NSDictionary *result = [mappingResult dictionary];

            if([[result objectForKey:@"success"] isEqualToNumber:[NSNumber numberWithInt:1]]){

                // some code
            }
        }

        failure:^(RKObjectRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
        }];

但我收到错误:

Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded."

0 个答案:

没有答案