ios - 使用 RestKit 发送简单的 GET 请求

标签 ios restkit restkit-0.20

我正在尝试使用 RestKit 发送一个简单的请求,我只对获取 JSON 感兴趣,

这是我的代码:

NSURL *endpoint = [NSURL URLWithString:@"https://www.ez-point.com/api/v1/"];
    RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:endpoint];
    [objectManager.HTTPClient setAuthorizationHeaderWithToken:@"xxxxxxxxxxx"];
    [objectManager getObjectsAtPath:@"ezpoints" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        NSLog(@"It works");
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"Request failed");
    }];

我得到的错误是:

    Restkit.network:RKObjectRequestOperation.m:243 GET 
    'https://www.ez-point.com/api/v1/ezpoints' (200 OK / 0 objects) 
    [request=0.0000s mapping=0.0000s total=1.6094s]: Error 
Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x160df470 {NSErrorFailingURLStringKey=https://www.ez-point.com/api/v1/ezpoints, 
    NSLocalizedFailureReason=A 200 response was loaded from the URL 'https://www.ez-point.com/api/v1/ezpoints', which failed to match all (0) response 
    descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=https://www.ez-point.com/api/v1/ezpoints, NSUnderlyingError=0x160a9730 "No mappable object representations were found at the key paths searched."}
        2013-10-28 15:03:40.899 EZ-POINT[1651:c07] Request failed

对这个问题有什么想法吗?

最佳答案

如错误所述,RestKit 无法为加载的响应找到任何响应描述符。那是因为你没有设置。

如果你只是想加载 JSON 而不是映射它,RestKit 可能有点过头了,你应该把赌注押在 AFNetworking 上。这也被 RestKit 使用:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

关于ios - 使用 RestKit 发送简单的 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19633122/

相关文章:

ios - 特定实体的 RestKit 映射

ios - RestKit 0.20.1 如何映射父 ID

ios - RestKit 和键值编码......如何解决重复元素?

ios - 休息套件 : Map relationship from JSON parentId

ios - RESTKit - 如何始终替换所有缓存的对象而不是更新?

ios - RestKit valueTransformer 未被调用

objective-c - MPMoviePlayerController 不播放视频

ios - Plot_Gallery_iOS 中的实时绘图不会更新 iPad 中的绘图范围

ios - 初始化对象的最佳方法是什么?

objective-c - Objective-C中的[ self 发布]是什么意思?