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 8132625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:23:32+00:00 2026-06-06T09:23:32+00:00

I have a simple NSDictionary that I am trying to populate with data from

  • 0

I have a simple NSDictionary that I am trying to populate with data from an external site via JSON that is returned. The JSON that is returned is fine but I am haveing trouble getting actual data for a specific key.

Here is the JSON data printed to the console.

This is my JSON data:

(
        {
        CategoryID = 12345;
        CategoryName = "Baked Goods";
    },
        {
        CategoryID = 12346;
        CategoryName = Beverages;
    },
        {
        CategoryID = 12347;
        CategoryName = "Dried Goods";
    },
        {
        CategoryID = 12348;
        CategoryName = "Frozen Fruit & Vegetables";
    },
        {
        CategoryID = 12349;
        CategoryName = Fruit;
    },
        {
        CategoryID = 12340;
        CategoryName = "Purees & Soups";
    },
        {
        CategoryID = 12341;
        CategoryName = Salad;
    },
        {
        CategoryID = 12342;
        CategoryName = "Snack Items";
    },
        {
        CategoryID = 12343;
        CategoryName = Vegetables;
    }
)

The error I am getting is:

Terminating app due to uncaught exception
‘NSInvalidArgumentException’, reason: ‘-[__NSCFArray
enumerateKeysAndObjectsUsingBlock:]: unrecognized selector sent to
instance 0x6884000’

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

    NSError *error = nil;
    // Get the JSON data from the website
    NSDictionary *categories = [NSJSONSerialization JSONObjectWithData:data  options:kNilOptions error:&error];

    if (categories.count > 0){
        NSLog(@"This is my JSON data %@", categories);

        [categories enumerateKeysAndObjectsUsingBlock: ^(__strong id key, __strong id obj, BOOL *stop) {
        NSLog(@"Key = %@, Object For Key = %@", key, obj); }];
}

I’m not sure why this is happening but I’m sure it’s something simple like I am using the incorrect object or something.

Help is appreciated.

  • 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-06-06T09:23:33+00:00Added an answer on June 6, 2026 at 9:23 am

    +JSONObjectWithData:options:error: is returning an NSArray not an NSDictionary. '-[__NSCFArray enumerateKeysAndObjectsUsingBlock:] is the key part of the error message. It tells you that you are calling -enumerateKeysAndObjectsUsingBlock: on an array.


    For this case, you could use -enumerateObjectsUsingBlock: instead.

    If you are not sure wether a NSArray or an NSDictionary will be returned, you can use -isKindOf:

    id result = [NSJSONSerialization …];
    if ([result isKindOf:[NSArray class]]) {
        NSArray *categories = result;
        // Process the array
    } else if ([result isKindOf:[NSDictionary class]]) {
        NSDictionary *categories = result;
        // Process the dictionary
    }
    

    From enumerateObjectsUsingBlock:

    Executes a given block using each object in the array, starting with the first object and continuing through the array to the last object.

    • (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block

    So it should be called as such

    [categories enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        NSLog(@"index = %d, Object For Key = %@", idx, obj);
    }];
    

    A quick read of the documentation really can save you lots of frustration.

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

Sidebar

Related Questions

I have simple shared memory DLL for interprocess data exchange from unmanaged to managed
I have a simple JSON string that looks like ( { ID = 1;
I have an NSDictionary that was converted from XML that is really confusing me.
I have simple html code that plays YouTube video after click on the image:
i have simple form that uploads image to server and returns php string containing
I'm trying to convert a sample from objective C to Monotouch, and I have
I have a simple iPhone app that Im learning and I want to have
I am trying to implement a Core Data backed UITableView that supports indexing (eg:
I'm creating an app that displays a random word (a key from an NSDictionary)
Hey guys, I have a Cocoa application that sends an NSDictionary over the network

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.