Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to mapping object by RestKit 0.20.x with complicate structure JSON
    text
    copied!<p>I'm using Restkit 0.20.x to mapping object from json like</p> <pre><code>{ "d":{ "results":[ { "Web":[ "key1":"value1", "key2":"value2" ], "Image":[ "key1":"value1", "key2":"value2" ], }, ], }, } </code></pre> <p>My main purpose to manage "Web" and "Image" key. I'm trying to mapping object but stuck at "results" key (value of key "results" is a array which has only one element as dictionary). How to using RestKit to map object in my case ?</p> <p>My fail implement:</p> <p>WFSD.h</p> <pre><code>@interface WFSD : NSObject @property (nonatomic, strong) WFSResults *results; @end </code></pre> <p>WFSResults.h</p> <pre><code>@interface WFSResults : NSObject @property (nonatomic, strong) WFSResult *result; @end </code></pre> <p>WFSResult.h</p> <pre><code>@interface WFSResult : NSObject @property (nonatomic, strong) WFSWeb *web; @property (nonatomic, strong) WFSImage *image; @end </code></pre> <p>MyController.m</p> <pre><code>RKObjectMapping* dMapping = [RKObjectMapping mappingForClass:[WFSD class]]; RKObjectMapping* resultsMapping = [RKObjectMapping mappingForClass:[WFSResults class]]; RKRelationshipMapping* rsMapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"results" toKeyPath:@"results" withMapping:resultsMapping]; [dMapping addPropertyMapping:rsMapping1]; RKObjectMapping* resultMapping = [RKObjectMapping mappingForClass:[WFSResult class]]; [resultsMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:nil toKeyPath:@"result" withMapping:resultMapping]]; RKRelationshipMapping* rsMapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Image" toKeyPath:@"Image" withMapping:imageMapping]; [resultMapping addPropertyMapping:rsMapping2]; RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dMapping pathPattern:nil keyPath:@"d" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload