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

  • Home
  • SEARCH
  • 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 6750431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:48:22+00:00 2026-05-26T12:48:22+00:00

This is my code: NSError *error = nil; SBJsonParser *parserJson = [[SBJsonParser alloc] init];

  • 0

This is my code:

    NSError *error = nil;
    SBJsonParser *parserJson = [[SBJsonParser alloc] init];
    NSDictionary *jsonObject = [parserJson objectWithString:webServiceResponse error:&error]; 
    [parserJson release], parserJson = nil;

    //Test to see if response is different from nil, if is so the parsing is ok
    if(jsonObject != nil){
        //Get user object
        NSDictionary *userJson = [jsonObject objectForKey:@"LoginPOST2Result"];
        if(userJson != nil){
            self.utente = [[User alloc] init];
            self.utente.userId = [userJson objectForKey:@"ID"];
        }

While Json string webServiceResponse is:

{"LoginPOST2Result":
    "{\"ID\":1,
    \"Username\":\"Pippo\",
    \"Password\":\"Pippo\",
    \"Cognome\":\"Cognome1\",
    \"Nome\":\"Nome1\",
    \"Telefono\":\"012345678\",
    \"Email\":null,
    \"BackOffice\":true,
    \"BordoMacchina\":false,
    \"Annullato\":false,
    \"Badge\":1234}"
}

The problem arise when is execute this line:

self.utente.userId = (NSInteger *) [userJson objectForKey:@"ID"];

and the error is:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x6861520'

The error seems to be due to the fact that the object userJson is not an NSDictionary but rather NSCFString type and therefore does not respond to the message objectForKey:.
Where am I doing wrong?

  • 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-26T12:48:23+00:00Added an answer on May 26, 2026 at 12:48 pm

    You need to better understand what is a pointer and what no in the Cocoa Framework.

    Infact you are defining userJson to NSDictionary and not NSDictionary *. Consider that all objects in Cocoa are pointers. Infact check that [NSDictionary objectForKey:] returns an “id” and then you must use NSDictionary *. Using simply NSDictionary you will refer to the class.

    Similar mistake is done later in the cast to (NSInteger *) but NSInteger (NSInteger is not an object, it’s a basic type hesitated from long or int (depends on the platform architecture) as you can see from its definition:

    
    #if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
    typedef long NSInteger;
    #else
    typedef int NSInteger;
    #endif
    

    And also it seems from the object definition above that the key you are trying to get is dumped as a string and you are trying to fetch a dictionary. Please check the original json which probably is not in the format you expect.

    So at the end you have at least 3 errors that will make your app crash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: NSError *error; // NSMigrationManager hates it if you don't provide
This code function LoadContent(Id) { alert('Controls/Network/NetworkDetail.aspx?' + rnd() + '&CtlId=' + Id); $.get('Controls/Network/NetworkDetail.aspx?' +
Details are in the comments. The following code: // Perform the fetch... NSError *error
I'm starting with the following snip to download an image NSError *error = nil;
Am getting errors in this piece of code; I have placed the error messages
OK, so this code below sometimes crashes on the line below //bug!! The error
I got into the habit of coding my error handling this way: NSError* error
I'm getting a EXC_BAD_ACCESS error when this code gets called NSLog(@Count: %@, [fetchedObjects count]);
Please consider this code: NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:[ NSURL URLWithString:url ]]; //
This code in JS gives me a popup saying i think null is a

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.