0
votes

I have the following JSON I want to load through restkit. I am using Restkit 0.2.3.

JSON Data :

{
    "meta": {
        "limit": 25,
        "cache-expiry": 3600
    },
    "objects": [
        {
            "name": "TREATmachine",
            "locality": "San Francisco",
            "street_address": "20th & Morrison S.E.",
            "cuisines": [
                "vegan",
                "european"
            ],
            "region": "CA",
            "phone": "(503) 308-8851",
            "postal_code": "94110",
            "categories": [
                "other",
                "restaurant"
            ],
            "has_menu": true,        
        }
    ]
}

Now for this I declared this class to handle all elements

@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSString* locality;
@property (nonatomic, retain) NSString* street_address;
@property (nonatomic, retain) NSArray * cuisines;
@property (nonatomic, retain) NSString* region;
@property (nonatomic, retain) NSString* phone;
@property (nonatomic, retain) NSString* postal_code;
@property (nonatomic, retain) NSArray * categories;
@property (assign) BOOL has_menu;

Now the mapping is done like so,

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Location class]];
[mapping addAttributeMappingsFromArray:@[@"name",@"locality", @"street_address", @"region",   
      @"phone", @"postal_code", @"country", @"lat", @"website_url", @"resource_uri"]];
[mapping addAttributeMappingsFromDictionary:@{ @"venueID": @"id"}];

After which I create a

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor   
        responseDescriptorWithMapping:mapping method:RKRequestMethodGET pathPattern:@"/Locations 
        /search/" keyPath:@"objects" statusCodes:statusCodeSet];

and it works fine in getting the data, but the problem I have is that I always get an object that is empty, no data in it.

I do not get a failure or error message, just empty objects.

What am I missing?

Edit : Put in the response descriptor code.

1
Show the details of your response descriptor. - Wain
Hi, I updated the question with my descriptor - Eddie
Have you turned on trace logging for the mapping to see what happens? - Wain
You got it, I kind of messed my mappings but by logging it I fopund the issue, man you are awesome, thanks a lot, I Don;t know how to make your comment an answer. - Eddie

1 Answers

0
votes

After getting the good idea of logging from @Wain, I added the following code to my view controller

  RKLogConfigureByName("RestKit", RKLogLevelWarning); 
  RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
  RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);

and it basically told me I wasn't mapping my data properly.

I don;t know whether people have a recommendation as to where shold the trace level mapping code go ? as in which file? AppDelegate?