I am trying to retrieve value for id:
{"id":1,"name":"XYZ"}
When I use:
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
NSArray * myPeople = [jsonData JSONValue];
NSString *name = [[NSString alloc] init];
NSDictionary *person = [myPeople objectAtIndex:[indexPath row]];
name = [NSString stringWithString:[person valueForKey:@"id"]];
name = [name stringByAppendingString:@". "];
name = [name stringByAppendingString:[person valueForKey:@"name"]];
name = [name stringByAppendingString:[person valueForKey:@"id"]];
cell.textLabel.text = name;
I get the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException'
reason: '-[NSCFNumber length]: unrecognized selector sent to instance 0x4e7f8b0
How can I fix this?
You are calling both
stringWithString:andstringByAppendingString:but then passing in anNSNumberYou need to get the string value of the
NSNumberor use a format like:
I would also consider changing the structure slightly to make it easier to follow like this:
For sorting you want to make sure you are not pulling that data every time you set up a cell (looks like you are) or it will be a terrible experience.
I’m sure someone can point you to a better way of sorting but the quickest thing I can think of is