How to Add An array into Array index by index in iOS? -


i newbie in ios development. want add json parsing data dictionary array key value in array add last array index in new array.

my code

-(void)fetcheddata:(nsdata *)responsedata {  if (responsedata.length > 0) {     nserror* error;      self.json = [nsjsonserialization jsonobjectwithdata:responsedata options:kniloptions error:&error];     if ([[_json objectforkey:@"data"] iskindofclass:[nsarray class]])     {         nsarray *arr = (nsarray *)[_json objectforkey:@"data"];         [self.imagearray addobjectsfromarray:arr];         [self.storeviewtable reloaddata];     }     self.storeviewtable.hidden=false;     }     nsmutablearray *imagearray=[[nsmutablearray alloc]init];     (index=0; index <[self.imagearray count]; index ++)     {         for(nsdictionary *dict in self.imagearray )         {             imagearray = [dict valueforkey:@"demopage"];             self.imagesa = imagearray;         }     }       nslog(@"array count %d",[self.imagesa count]);      nslog(@"another array count %d",[self.imagearray count]); } 

here self.imagearray main array contain json data want parse new data old data , add in self.imagesa array here self-images value key demo page , self.imagearray count three(3) want 3 index value in self.imagesa contain last index value please give me solution that.and webservices link here. link

your code should below.

id json = [nsjsonserialization jsonobjectwithdata:responsedata options:kniloptions error:&error]; if ([[json objectforkey:@"data"] iskindofclass:[nsarray class]]) {     nsarray *arr = (nsarray *)[json objectforkey:@"data"];     [imagearray addobjectsfromarray:arr]; }  //do not alloc init if have alloc init array. nsmutablearray *imagesa=[[nsmutablearray alloc]init]; for(nsdictionary *dict in imagearray ) {     [imagesa addobject:@{@"demopage":[dict valueforkey:@"demopage"]}]; }  nslog(@"array count %lu",(unsigned long)[imagesa count]); nslog(@"another array count %lu",(unsigned long)[imagearray count]); 

and got below output

array count 3

another array count 3

note

and if want add demopage dictionary imagesa array replace loop

for(nsdictionary *dict in imagearray ) {     nsarray *arr = (nsarray *)[dict valueforkey:@"demopage"];     [imagesa addobjectsfromarray:arr]; } 

and output

array count 69

another array count 3


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -