Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6759049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:53:06+00:00 2026-05-26T13:53:06+00:00

I am trying to retrieve value for id : {id:1,name:XYZ} When I use: NSString

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:53:07+00:00Added an answer on May 26, 2026 at 1:53 pm

    You are calling both stringWithString: and stringByAppendingString: but then passing in an NSNumber

    You need to get the string value of the NSNumber

    [[person valueForKey:@"id"] stringValue];
    

    or use a format like:

    name = [NSString stringWithFormat:@"%@%@", name, [person valueForKey:@"id"]];
    

    I would also consider changing the structure slightly to make it easier to follow like this:

    NSDictionary *person = [myPeople objectAtIndex:[indexPath row]];
    NSString *personName = [person valueForKey:@"name"];
    NSSNumber *personId  = [person valueForKey:@"id"];
    
    NSString *name = [NSString stringWithFormat:@"%@. %@ %@", personId, personName, personId];
    

    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

    NSArray *myPeople = [[jsonData JSONValue] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
      return [[obj1 objectForKey:@"id"] compare:[obj2 objectForKey:@"id"]];
    }]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to search mongo collection to retrieve some value based on variable name,
I am trying to retrieve a value from an Array. Here is the code:
I am trying to store/retrieve a value that is stored in the Application Settings.
I am trying to retrieve the correct value from an ArrayList of objects (.NET
I'm trying to retrieve mulitple checked value, which are being showed in JSP dynamically,
I'm trying to retrieve an XML stream from a URL. For most URLs my
I am trying to retrieve the attribute name and type that exist in an
I am trying to retrieve the class name of an object. When I tried
I'm trying to retrieve the return value of a stored procedure in SQL Server
I am trying to use a dynamic linq query to retrieve an IEnumerable<T> from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.