Question

In the image below is the JSON that I'm getting back.

Below is my code mapping:

+(RKMapping *)googleMapping
{
    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[mappingModel class]];

    [mapping addAttributeMappingsFromDictionary:@{
                                                  @"description" : @"description",
                                                  @"reference" : @"reference"
                                                  }];
    return mapping;
}

Fetch:

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping
                                                                                            method:RKRequestMethodGET
                                                                                       pathPattern:nil
                                                                                       keyPath:@"predictions" statusCodes:statusCodeSet];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request
                                                                    responseDescriptors:@[responseDescriptor]];

[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

    NSLog(@"mappingResults %@", mappingResult);

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

}];
[operation start];

NSLog:

2014-03-22 12:42:03.988 Google+RESTKit[21229:60b] I restkit.network:RKObjectRequestOperation.m:180 GET 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=cofee&sensor=true&key=1234&location=0.000000,0.000000&radius=100.000000'
2014-03-22 12:42:04.031 Google+RESTKit[21229:6a03] I restkit.network:RKObjectRequestOperation.m:250 GET 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=cofee&sensor=true&key=1234&location=0.000000,0.000000&radius=100.000000' (200 OK / 5 objects) [request=0.0430s mapping=0.0007s total=0.0474s]
2014-03-22 12:42:04.032 Google+RESTKit[21229:60b] mappingResults <RKMappingResult: 0x1733ecf0, results={
    predictions =     (
    "Coffee Road, Modesto, CA, United States",
    "Coffee Bay, Eastern Cape, South Africa",
    "Coffee Road, Bakersfield, CA, United States",
    "Coffeeville, MS, United States",
    "Coffeen, IL, United States"
    );
}>

The mappingResult that returns should be an array with NSDictionary Objects? It seems to return the value of "description" in an array and there is no "reference" value. What am I doing wrong?

Returned JSON:

enter image description here

Was it helpful?

Solution

description is a defined method name, so by adding your own property with the same name you're overriding the default implementation. So, you do have the objects you expect, but the log prints something you aren't expecting.

Change the name of your property so it doesn't overlap with description.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top