Вопрос

I'm new to RestKit and Objective C. I'm trying to retrieve data from a Web Service with RestKit. I have done the mapping but some how I'm getting the error that it could not find a match for the response. I am using Mapping without KVC as the JSON format has no key.

Here is the mapping implementation

+(RKObjectMapping *)venueMapping {
     RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[venue class]];
     NSDictionary *mappingDictionary = @{@"name":@"name"};
    [mapping addAttributeMappingsFromDictionary:mappingDictionary];

    return mapping;
 } 

I am trying with only one value to see if anything matches. Below is the response descriptor

-(void) loadVenue:(void (^)(venue *))success failure:(void (^)(RKObjectRequestOperation *, NSError *))failure{

     RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
     [self getObjectsAtPath:@"venue" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){

    if(success){
        venue *venues = (venue *)[mappingResult.array firstObject];
        success(venues);
    }

    }failure:^(RKObjectRequestOperation *operation, NSError *error){
        if(failure){
           failure(operation,error);
    }
}];

}

- (void) setupResponseDescriptors {
[super setupResponseDescriptiors];

RKResponseDescriptor *authenticatedUserResponseDescriptors = [RKResponseDescriptor responseDescriptorWithMapping:[MappingProvider venueMapping] method:RKRequestMethodGET pathPattern:@"venue" keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self addResponseDescriptor:authenticatedUserResponseDescriptors];
}

I have been reading the documentation and trying out various ways, but I have still zero solution for this. Anyone has any idea?

Attached is a sample JSON return.

 (
    {
    coverType = "<null>";
    description = "";
    name = "McDonald";
    priv = 1;
    rates = ();
    },
    {
    coverType = "<null>";
    description = "";
    name = "My House";
    priv = 1;
    rates =();
    },
 )

Added TraceLog

2014-04-22 21:45:55.636 App_Test[420:60b] I restkit:RKLog.m:34 RestKit logging initialized...
2014-04-22 21:45:56.064 App_Test[420:60b] I restkit.network:RKObjectRequestOperation.m:180 GET 'http://api.kontakt.io/venue'
2014-04-22 21:46:46.327 App_Test[420:f03] D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: (
        {
        beacons =         (
        );
        beaconsCount = 0;
        coverType = "<null>";
        description = "";
        id = "212321";
        lat = "<null>";
        lng = "<null>";
        managers =         (
        );
        name = McDonald;
        priv = 1;
        rates =         (
        );
        users =         (
        );
    }
)
 and targetObject: (null)
2014-04-22 21:46:46.328 App_Test[420:f03] D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: (null)
2014-04-22 21:46:46.328 App_Test[420:570b] E restkit.network:RKObjectRequestOperation.m:243 GET 'http://api.kontakt.io/venue' (200 OK / 0 objects) [request=0.9645s mapping=0.0000s total=50.3422s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x9556ab0 {NSErrorFailingURLStringKey=http://api.kontakt.io/venue, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://api.kontakt.io/venue', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://api.kontakt.io/venue, NSUnderlyingError=0x9557c30 "No mappable object representations were found at the key paths searched."}
Это было полезно?

Решение

The error message says:

which failed to match all (0) response descriptors

This indicates (due to the (0) in the message) that the setupResponseDescriptors method is not being called so no response descriptors are being added to the object manager.

Другие советы

You are attempting to get object at path "venue", but there doesn't appear to be any indication that you have a "venue" object in your JSON.

If you are not using CoreData, be sure Restkit is defined in your Podfile as follows

pod 'RestKit/Network', '~> 0.23' pod 'RestKit/ObjectMapping', '~> 0.23'

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top