ios - Accessing Dictionary objects From Web Service returning SIGABRT -


i have table view in each cell i'd have data populated in them web service. each cell supposed display name of object, price, , brand name. can name fine, price , brand name aren't coming easy. checked web service , have prices , brand names it's problem code. here's how looks far:

    (nsdictionary *objitem in resultsarray) {      nsstring *currentitemname = [objecttitlesarray objectatindex:indexpath.row];      if ([currentitemname isequaltostring:objitem[@"title"]])     {         cell.namelabel.text = currentitemname;         cell.pricelabel.text = objitem[@"price"];         cell.brandlabel.text = objitem[@"brands"];      } } 

objecttitlesarray array made separately contains names of objects returned, that's why can name easily.

here inside resultsarray:

<__nsarrayi 0x8cb9900>( { asins =     ( ); "best_page" =     {     currency = usd;     deeplink = "http://www.textbooks.com/iphone-book-covers-iphone-4s-iphone-4-and-iphone-3gs/9780321832764/scott-kelby.php";     description = "\"excellent marketplace listings \"\"iphone book: covers iphone 4s, iphone 4, , iphone 3gs\"\" scott kelby starting low $1.99!\"";     "image_url" = "http://images.textbooks.com/textbookinfo/covers/0321832760.gif";     "in_stock" = 1;     "live_price_url" = "http://api.invisiblehand.co.uk/v1/pages/live_price?url=http%3a%2f%2fwww.textbooks.com%2fiphone-book-covers-iphone-4s-iphone-4-and-iphone-3gs%2f9780321832764%2fscott-kelby.php";     "original_url" = "http://www.textbooks.com/iphone-book-covers-iphone-4s-iphone-4-and-iphone-3gs/9780321832764/scott-kelby.php";     pnp = "3.99";     price = "24.99";     "price_confidence" = low;     region = us;     "retailer_name" = "textbooks.com";     title = "iphone book: covers iphone 4s, iphone 4, , iphone 3gs"; }; brands =     (     pearson ); categories =     ( ); eans =     (     9780321832764 ); id = 10a9fb4e3868f5289dc0d53af80ae86a; "image_url" = "http://images.textbooks.com/textbookinfo/covers/0321832760.gif"; isbns =     (     0321832760 ); models =     ( ); mpns =     (     0321832760 ); "number_of_pages" = 1; resource = "/products/10a9fb4e3868f5289dc0d53af80ae86a"; title = "iphone book: covers iphone 4s, iphone 4, , iphone 3gs"; upcs =     ( ); }, 

all appreciated, , in advance.

edit:

changed code this:

for (nsdictionary *objitem in resultsarray) {      nsstring *currentitemname = [objecttitlesarray objectatindex:indexpath.row];      if ([currentitemname isequaltostring:objitem[@"title"]])     {         if (cell.pricelabel.text != (id)[nsnull null] && cell.pricelabel.text.length != 0 && cell.brandlabel.text != (id)[nsnull null] && cell.brandlabel.text.length != 0)         {           cell.namelabel.text = currentitemname;         nsdictionary *bestpagedictionary = objitem[@"best_page"];         cell.pricelabel.text = bestpagedictionary[@"price"];         nsarray *brandsarray = objitem[@"brands"];         cell.brandlabel.text = [brandsarray firstobject];         }      } } 

and getting nsinvalidargumentexception', reason: '-[__nscfnumber length]: unrecognized selector sent instance 0x8c98c00'

your dictionary structure not match data you're trying out of it.

  • brands array, not string. happen contain single string element, need grab that.

    nsarray *brandsarray = objitem[@"brands"]; cell.brandlabel.text = [brandsarray firstobject]; 
  • price not in top level dictionary nested in 1 inside it.

    nsdictionary *bestpagedictionary = objitem[@"best_page"]; cell.pricelabel.text = bestpagedictionary[@"price"]; 

edit looks price may number though appears string. try this:

nsdictionary *bestpagedictionary = objitem[@"best_page"]; nsnumber *price = bestpagedictionary[@"price"]; cell.pricelabel.text = [nsstring stringwithformat:@"%@", price]; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -