i trying use latest restkit in 1 of iphone app.
the json string
{ "testdata": 1374226642, "errorcode": null, "errormessage": null, "mycontent": { "myid": "1", "name": "mrbala", "textmessage": [ "text1231", "text1232", "text1234" ], "picturemessage": [ "text1231", "text1232", "text1234" ], "mydate": "0", "yourdate": "0" } }
my code follows.
@interface textmessage : nsobject @property (nonatomic,strong)nsstring *textmessage; @end picturemessage
@interface picturemessage : nsobject @property (nonatomic,copy)nsstring *picturemessage; @end my content
@interface mycontent : nsobject @property (nonatomic,copy)nsstring *myid; @property (nonatomic,copy)nsstring *name; @property (nonatomic,copy)nsarray *textmessage; @property (nonatomic,copy)nsarray *picturemessage; @property (nonatomic,copy)nsstring *mydate; @property (nonatomic,copy)nsstring *yourdate; @end mainitem
@interface weatherservice : nsobject @property (nonatomic,copy) nsdate *testdata; @property (nonatomic,copy) nsstring *errorcode; @property (nonatomic,copy) nsstring *errormessage; @property (nonatomic,strong)mycontent *mycontent; @end mappings
[rkmimetypeserialization registerclass:[rknsjsonserialization class] formimetype:@"text/html"]; rkobjectmapping *textmessage = [rkobjectmapping mappingforclass:[textmessage class]]; [textmessage addpropertymapping:[rkattributemapping attributemappingfromkeypath:nil tokeypath:@"textmessage"]]; rkobjectmapping *picturemessage = [rkobjectmapping mappingforclass:[picturemessage class]]; [picturemessage addpropertymapping:[rkattributemapping attributemappingfromkeypath:nil tokeypath:@"picturemessage"]]; rkobjectmapping *mycontent = [rkobjectmapping mappingforclass:[mycontent class]]; [mycontent addattributemappingsfromdictionary:@{@"myid": @"myid", @"name" : @"name", @"mydate":@"mydate", @"yourdate":@"yourdate"}]; [mycontent addpropertymapping:[rkrelationshipmapping relationshipmappingfromkeypath:@"textmessage" tokeypath:@"textmessage" withmapping:textmessage]]; [mycontent addpropertymapping:[rkrelationshipmapping relationshipmappingfromkeypath:@"picturemessage" tokeypath:@"picturemessage" withmapping:picturemessage]]; rkobjectmapping *mainitem = [rkobjectmapping mappingforclass:[mainitem class]]; [mainitem addattributemappingsfromdictionary:@{ @"testdata" : @"requestdate", @"errorcode" : @"errorcode", @"errormessage" : @"errormessage"}]; [mainitem addpropertymapping:[rkrelationshipmapping relationshipmappingfromkeypath:@"newscontent" tokeypath:@"newscontent" withmapping:mycontent]]; nsindexset *statuscodes = rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful); // in 2xx rkresponsedescriptor *responsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:mainitem method:rkrequestmethodany pathpattern:nil keypath:@"" statuscodes:statuscodes]; nsstring *lurl = @"http://xxx.xxx.143.139/test.json"; nsstring *lmodified = [[lurl stringbyaddingpercentescapesusingencoding:nsutf8stringencoding] stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]]; nsurl *url = [nsurl urlwithstring:lmodified]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; rkobjectrequestoperation *objectrequestoperation = [[rkobjectrequestoperation alloc]initwithrequest:request responsedescriptors:@[responsedescriptor]]; [objectrequestoperation setcompletionblockwithsuccess:^(rkobjectrequestoperation *operation, rkmappingresult *mappingresult){ rkloginfo(@"load collection of articles : %@",mappingresult.array); nsmutablearray *larray =[[nsmutablearray alloc]initwitharray:mappingresult.array]; (int i=0; < [mappingresult.array count]; i++) { mainitem *larticle = [larray objectatindex:i]; (int l=0;l < larticle.newscontent.textmessage.count; l++){ textmessage *lmessage = [larticle.newscontent.textmessage objectatindex:l]; nslog(@"message :: %@",[lmessage textmessage]); } (int l=0;l < larticle.newscontent.picturemessage.count; l++){ picturemessage *lmessage = [larticle.newscontent.picturemessage objectatindex:l]; nslog(@"picture :: %@",[lmessage picturemessage]); } nslog(@"article :: %@",[larticle requestdate]); } }failure:^(rkobjectrequestoperation *operation, nserror *error) { rklogerror(@"operation failed :: %@",error); }]; [objectrequestoperation start]; everything works fine. when try print message text, prints complete mapping info. line nslog(@"message :: %@",[lmessage textmessage]); prints complete mapping info. cannot access textmessage. output.
message :: text1231 ({ http = { request = { url = "http://xxx.xxx-xxx.xx/mycontent/?id=1"; headers = { }; method = get; }; response = { url = "http://xxx.xxx-xxx.xx/mycontent/?id=1"; headers = { connection = "keep-alive"; "content-type" = "text/html; charset=utf-8"; date = "fri, 19 jul 2013 11:12:16 gmt"; server = "apache/2.2.22"; "set-cookie" = "fe_typo_user=9862282e43cabf58a4226fe92338877b; path=/"; "transfer-encoding" = identity; "x-pad" = "avoid browser bug"; "x-powered-by" = "php/5.3.19"; }; }; }; mapping = { collectionindex = 2; rootkeypath = ""; }; })
is there missing part in ?
regards,
nirav
Comments
Post a Comment