objective c - Mapping nested objects and arrays -


good afternoon, everyone!

i'm trying figure out how map objects nested arrays, project keeps being terminated due uncaught exception. assume i'm not mapping correctly, i'm being told isn't key-value coding compliant.

how map object nested array?

following footprint of json i'm trying map, interface , implementation, , error that's being throw, respectively. finally, there link project on github, incase i've left out, or seeing full source helpful.

json

{   "href": "string",   "items": [     {       "type": "string",       "status": "string",       "name": "string",       "publisher": "string",       "publisherid": "string",       "description": "string",       "url": "string",       "smalllogoimageurl": "string",       "tileimageurl": "string",       "heroimageurl": "string",       "tags": [         "string",         "string"       ],       "createdon": "2015-04-22t18:55:40.782z",       "downloadurl": "string",       "getproductcodeurl": "string",       "metadata": {         "exetype": "string",         "packagefilename": "string",         "installdirectory": "string",         "executablename": "string"       },       "id": "string"     }   ] } 

interface (.h)

@interface sfrontpageitem : nsobject  @property (nonatomic, strong) nsstring *type; @property (nonatomic, strong) nsstring *status; @property (nonatomic, strong) nsstring *name; @property (nonatomic, strong) nsstring *publisher; @property (nonatomic, strong) nsstring *publisherid; @property (nonatomic, strong) nsstring *productdescription; @property (nonatomic, strong) nsstring *url; @property (nonatomic, strong) nsstring *smalllogoimageurl; @property (nonatomic, strong) nsstring *tileimageurl; @property (nonatomic, strong) nsstring *heroimageurl; @property (nonatomic, strong) nsarray *tags; @property (nonatomic, strong) nsstring *createdon; @property (nonatomic, strong) nsstring *downloadurl; @property (nonatomic, strong) nsstring *getproductcodeurl; @property (nonatomic, strong) nsarray *metadata; @property (nonatomic, strong) nsstring *productid;  @end   @interface sfrontpage : nsobject  @property (nonatomic, strong) nsstring *href; @property (nonatomic, strong) nsarray *items;  @end 

implementation (.m)

- (void) getfrontpage {      appdelegate *appdelegate = [[nsapplication sharedapplication] delegate];      rkobjectmapping *itemmapping = [rkobjectmapping mappingforclass:[sfrontpageitem class]];      [itemmapping addattributemappingsfromdictionary:@{                                                         @"type": @"type",                                                         @"status": @"status",                                                         @"name": @"name",                                                         @"publisher": @"publisher",                                                         //@"publisherid": @"publisherid",                                                         @"description": @"description",                                                         @"url": @"url",                                                         //@"smalllogoimageurl": @"smalllogoimageurl",                                                         @"tileimageurl": @"tileimageurl",                                                         //@"heroimageurl": @"heroimageurl",                                                         //@"tags": @"tags",                                                         @"createdon": @"createdon",                                                         //@"downloadurl": @"downloadurl",                                                         //@"getproductcodeurl": @"getproductcodeurl",                                                         //@"metadata": @"metadata",                                                         @"id": @"productid"                                                     }];     //itemmapping.forcecollectionmapping = yes;       rkobjectmapping *frontpagemapping = [rkobjectmapping mappingforclass:[sfrontpage class]];     [frontpagemapping addattributemappingsfromdictionary:@{                                                            @"href": @"href"                                                         }];       [frontpagemapping addpropertymapping:[rkrelationshipmapping relationshipmappingfromkeypath:@"items"                                                                                      tokeypath:@"items"                                                                                    withmapping:itemmapping]];       rkresponsedescriptor *responsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:frontpagemapping                                                                                             method:rkrequestmethodget                                                                                        pathpattern:nil                                                                                            keypath:nil                                                                                        statuscodes:rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful)];      [self.objectmanager.httpclient setauthorizationheaderwithusername:self.sconnection.apikey.key password:self.sconnection.apikey.secret];     [self.objectmanager addresponsedescriptor:responsedescriptor];     [self.objectmanager getobjectsatpath:@"/api/frontpage/rest" parameters:nil         success:^(rkobjectrequestoperation *operation, rkmappingresult *result)         {              sfrontpage *newfrontpage = result.firstobject;             nslog (@"   href: %@", newfrontpage.href);              //nslog (@"items: %@", newfrontpage.items.firstobject);             //sfrontpageitem *newfrontpageitem = newfrontpage.items.firstobject;             //nslog (@"unexpected great thing %@", newfrontpageitem );              [appdelegate.loginviewcontroller apiconnectionsuccess];           } failure:^(rkobjectrequestoperation *operation, nserror *error)         {              [appdelegate.loginviewcontroller updateloginwindowheaderlabelto:@"unable load frontpage"];             [appdelegate.loginviewcontroller apiconnectionfailure];         }]; } 

error

[<sfrontpageitem 0x6180001026d0> setvalue:forundefinedkey:]: class not key value coding-compliant key description. 

source

the full source can found on github, relevant files being apimanager.h & apimanager.m.

i hope i've been clear enough, miss mark when forming question don't understand. i'm new both objc, , restkit, i'm sure there lot of confusing things in code. taking time read through it, , consider question. if can clarify anything, please let me know!

michael

you map description description, property has identifier productdescription. change mapping or property name.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -