I parsed my JSON perfectly, but my server just changed to me. My JSON looked like this:
{ "blobs": [ { "createdOn": "2012-03-16T15:13:12.551Z", "description": "Fake description", "hint": "And a useless hint", "id": 400, "name": "Fake CA one", "publicId": "FF6", "type": 0 }, { "createdOn": "2012-03-16T17:33:48.514Z", "description": "No hint on this one, but it does have a description.", "hint": "Hint", "id": 402, "name": "Second fake one in CA", "publicId": "FF8", "type": 0 } ] }
and my comparison looked like this:
RKObjectMapping* blobMapping = [RKObjectMapping mappingForClass:[GetResponseInRegionResponse class]]; [blobMapping mapKeyPath:@"name" toAttribute:@"name"]; [blobMapping mapKeyPath:@"id" toAttribute:@"blobId"]; [blobMapping mapKeyPath:@"description" toAttribute:@"description"]; [blobMapping mapKeyPath:@"hint" toAttribute:@"hint"]; [[RKObjectManager sharedManager].mappingProvider setMapping:blobMapping forKeyPath:@"blobs"];
Now my server has changed and I will return it:
{ "blobsList": { "blobs": [ { "createdOn" :"2012-03-16T15:13:12.551Z", "description": "Fake description", "hint": "And a useless hint", "id": 400, "name": "Fake CA one", "publicId": "FF6", "type": 0 }, { "createdOn": "2012-03-16T17:33:48.514Z", "description": "No hint on this one, but it does have a description.", "hint": "Hint", "id": 402, "name": "Second fake one in CA", "publicId": "FF8", "type": 0 } ] } }
So I added this to my display:
RKObjectMapping* blobsListMapping = [RKObjectMapping mappingForClass:[GetResponseInRegionResponseList class]]; [blobsListMapping mapKeyPath:@"blobsList" toAttribute:@"blobsList"]; [[RKObjectManager sharedManager].mappingProvider setMapping:blobsListMapping forKeyPath:@"blobsList"];
And there are my classes:
@interface GetResponseInRegionResponse : NSObject { NSString* name; NSString* blobId; NSString* description; NSString* hint; } @interface GetResponseInRegionResponseList : NSObject { NSArray *blobsList; }
When I parse this JSON, I get one object that has a JKArray of 2 objects, both of which are JKDictionary objects. Itβs so clear that this is my data, but it is in the form of a JKDictionary. It never matched the GetResponseInRegionResponse class!
From reading github docs, it seems like I want to use the toRelationship method for arrays, but I just don't see where to put it. If I follow the example of an βarticleβ and try:
[blobListMapping mapKeyPath:@"blobs" toAttribute:@"blobsList"]; [blobListMapping mapKeyPath:@"blobs" toRelationship:@"blobsList" withMapping:blobMapping];
I get this exception:
2012-03-19 14:59:53.704 Ferret[8933:16303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to add mapping for keyPath blobsList, one already exists...'
So how can I match an array complex objects inside my json?
I appreciate any help. Thanks!