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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:52:44+00:00 2026-06-15T04:52:44+00:00

I am trying to parse a JSON array returned by a RESTful web API

  • 0

I am trying to parse a JSON array returned by a RESTful web API that looks similiar to the following (using jsonviewer the json is returned as a bunch of dictionaries in an array):

[{
"date": "2011-03-21",
"meal": "BREAKFAST",
"category": "BREAKFAST BAKERY",
"recipe": "213012",
"name": "Aesops Bagels",
"portion": "1",
"unit": "each"},

I am trying to get the “name” information and then store it into an tableview. Here is the code I am using to accomplish that:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSArray *allDataArray = [NSJSONSerialization JSONObjectWithData:webData 
                                                            options:0 
                                                              error:nil];

    for (NSDictionary *diction in allDataArray) {
        NSDictionary *menuItem = [diction objectForKey:@"menuItem"];
        NSString *name = [menuItem objectForKey:@"name"];

        [array addObject:name];
    }

    [[self MyTableView]reloadData];
}

The error that I am getting is:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil’

So I’m pretty sure that there is an error occurring in the line above the for loop, and this is causing the array to try to take nil as a value. But any help figuring out what is going wrong/how to successfully parse this json would be extremely appreciated. I am very new to both json, xcode, and iOS so I apologize if I have done anything particularly stupid.

  • 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-15T04:52:45+00:00Added an answer on June 15, 2026 at 4:52 am

    You don’t actually have an item called menuItem in your JSON sample. Your code looks as it was written to parse JSON that looks like this:

    [{ "menuItem" : { "name" : "Aesops Bagels",
                      …
                    }
     },
    ]
    

    ie, its expecting a “menuItem” key in each dictionary in the list.
    If you’re actually trying to parse the snippet you posted, I think you just need to simplify your loop code from this:

    NSDictionary *menuItem = [diction objectForKey:@"menuItem"];
    NSString *name = [menuItem objectForKey:@"name"];
    

    to:

    NSString *name = [diction objectForKey:@"name"];
    

    You may also want to make sure that name isn’t nil before you attempt to add it to your results array, just in case your data has an entry that’s missing a name.

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

Sidebar

Related Questions

I'm trying to consume a RESTful JSON web service using WCF on the client
I am trying to parse out data from oodle.com api feed using the JSON.NET
I'm trying to parse some json using Json.NET. The json either returns an array
I'm trying to parse the following JSON string returned by httpResponse : { message
I am trying to parse some JSON that I get via a web service.
I'm trying to parse a JSON object that consists of an array of objects.
I'm trying to parse this JSON Array: http://www.ifanatic.hu/api/get_recent_posts/?dev=1 But I get this error: 2012-07-15
I am trying to parse the json values from the following stream: {id: tag:search.xxxxx.com,2005:xxxxxxxxxxx}
I;m trying to parse a json string which I receive from web server as
I am trying to parse the following JSON string remotely: [{name:Object1,data:[1,2]},{name:Object2,data:[3,4]}] I am doing

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.