Restkit无法匹配响应描述符

时间:2015-09-08 06:43:56

标签: ios objective-c iphone restkit restkit-0.20

这是我的JSON:How to write image metadata

这是我的Mapper:

-(RKObjectManager *)mapContact{
    RKObjectMapping* dataMapping = [RKObjectMapping mappingForClass:[Data class]];
    [dataMapping addAttributeMappingsFromDictionary:@{
                                                      @"Data": @"app_data",
                                                      @"message": @"app_message",
                                                      @"status":@"app_status",
                                                      @"Success": @"app_success"
                                                      }];

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dataMapping method:RKRequestMethodGET pathPattern:nil keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

    RKEntityMapping* contactMapping = [RKEntityMapping mappingForEntityForName:@"Contact" inManagedObjectStore:managedObjectStore];
    contactMapping.identificationAttributes = @[@"con_id"];
    [contactMapping addAttributeMappingsFromDictionary:@{
                                                                @"content": @"con_content",
                                                                @"id"     : @"con_id",
                                                                @"title"  : @"con_title",
                                                                @"language":@"con_language",
                                                                }];

    RKResponseDescriptor *responseDescriptor2 = [RKResponseDescriptor responseDescriptorWithMapping:contactMapping
                                                                                             method:RKRequestMethodGET
                                                                                        pathPattern:nil
                                                                                            keyPath:@"data.contentblock"
                                                                                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

    NSArray *arrResponsDescriptor = [[NSArray alloc]initWithObjects:responseDescriptor,responseDescriptor2,nil];

    [objectManager addResponseDescriptorsFromArray:arrResponsDescriptor];
    return objectManager;

}

这是我的网络服务电话:

-(void)fetchContactOnCompletion:(myCompletion) compblock{
    Mapper *mapper = [Mapper new];
    RKManagedObjectStore *store = [[ASLDataModel sharedDataModel] objectStore];
    NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
    RKObjectManager *objectManager = [mapper mapContact];


    NSString *urlString = [NSString stringWithFormat:@"webservice/content/get/apikey/%@/language/%@/contentid/2",apikey,language];

    NSURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:urlString parameters:nil];



    RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:context success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        Data *data = [mappingResult.dictionary valueForKey:@""];
        if([data.app_status isEqualToNumber:@200]){
            NSError *error = nil;
            BOOL success = [context  save:&error];
            if (!success) RKLogWarning(@"Failed saving managed object context: %@", error);
            NSError *saveError = nil;
            compblock(YES);
        }else{
            compblock(NO);
        }
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {

    }];
    [objectManager enqueueObjectRequestOperation:operation];
}

我得到了这些错误:

2015-09-08 08:38:56.431 ASLTravel[17377:427756] D restkit.object_mapping:RKMapperOperation.m:433 Finished performing object mapping. Results: (null)
2015-09-08 08:38:56.432 ASLTravel[17377:427753] E restkit.network:RKObjectRequestOperation.m:209 GET 'http://asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2' (200 OK / 0 objects) [request=1.6674s mapping=0.0000s total=1.6899s]:
error=Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x7f9413f8b730 {NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2', which failed to match all (2) response descriptors:
  <RKResponseDescriptor: 0x7f9413f535e0 baseURL=http://asl-travel.be/ pathPattern=(null) statusCodes=200-299> failed to match: response URL 'http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2' is not relative to the baseURL 'http://asl-travel.be/'.
  <RKResponseDescriptor: 0x7f9413f2b1e0 baseURL=http://asl-travel.be/ pathPattern=(null) statusCodes=200-299> failed to match: response URL 'http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2' is not relative to the baseURL 'http://asl-travel.be/'., NSErrorFailingURLStringKey=http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2, NSErrorFailingURLKey=http://www.asl-travel.be/webservice/content/get/apikey/asl001/language/nl/contentid/2, NSUnderlyingError=0x7f9413c2fc20 "No mappable object representations were found at the key paths searched.", keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.}

任何人都可以帮我这个吗?我现在几个小时都在寻找这个问题...

非常感谢!

1 个答案:

答案 0 :(得分:0)

Web服务正在将您重定向到www.asl-travel.be,因此模式匹配器永远不会找到匹配项。更新基本URL或关闭重定向以解决此问题。