objective c - Extract data from Json into Label Text IOS -


so using pokedex api learning curve ios , web services,

here didrecivedata when connection completes

- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data{     //if resposne recieved call function     // nslog(@"data %@", data);      //nsstring *mystring = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];      //nslog(@"string %@", mystring);     //put data string      nserror *e = nil;      pokedictionary = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers error:&e];      nslog(@"dictionary %@", pokedictionary);  } 

this outputs json console, can log console this

- (void)connectiondidfinishloading:(nsurlconnection *)connection {      // data      // receiveddata declared method instance elsewhere      nslog(@"succeeded!");      nslog(@"the pokemon's name %@", pokedictionary[@"name"]);     nslog(@"the pokemon's attack %@", pokedictionary[@"attack"]);     nslog(@"the pokemon's speed %@", pokedictionary[@"speed"]);        } 

however tried extract json text fields this

{      self.pokemonattack.text = (@"the pokemon's speed %@", pokedictionary[@"name"]);     self.pokemonattack.text = (@"the pokemon's speed %@", pokedictionary[@"attack"]);     self.pokemonspeed.text = (@"the pokemon's speed %@", pokedictionary[@"speed"]);    } 

error "expression result unused", guess main issue not comfortable objective-c , hacking around in ios. apologise , understand comments of saying objective-c courses

if can point me in right direction can continue trial fire, guess should moving swift soon

first of should know delegate method connection:didreceivedata: may called multiple times connection loads data incrementally. may called once if returned data short, break @ point you'll end trying parse incomplete data.

regarding warning you're getting - can't format strings that. you're trying use string formatting you're calling nslog, nslog method formatting you. need this:

self.pokemonattack.text = [nsstring stringwithformat:@"the pokemon's speed %@", pokedictionary[@"speed"]]; 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -