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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:26:38+00:00 2026-06-15T10:26:38+00:00

When parsing JSON, I get NSDictionary and go through it one (known) key at

  • 0

When parsing JSON, I get NSDictionary and go through it one (known) key at a time. When debugging a bug, I started wondering: how should I handle missing key vs value which is zero?

Earlier I would have used something like this to check if key exists or not:

    if ([dict objectForKey:@"public"])
        newItem.isPublic = [dict objectForKey:@"public"] ? YES : NO;

but now I wrote this using Objective-C object literals. Just started wondering, what does this check actually do:

    if (dict[@"public"])
        newItem.isPublic = dict[@"public"] ? @YES : @NO;

Should I check against nil or [NSNull null] or is there some easier, obvious, way?

  • 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-15T10:26:39+00:00Added an answer on June 15, 2026 at 10:26 am

    The new literal syntax makes no difference here. The dict[@"public"] code is translated into [dict objectForKeyedSubscript:@"public"], which is documented to be the same as valueForKey:, which in turn calls objectForKey:.

    As for the conditional test, writing if ([dict objectForKey:@"foo"]) is the same as if ([dict objectForKey:@"foo"] != nil). In other words, [NSNull null] counts as true here, so you have to check explicitly if you want a different behaviour. Zero can’t be directly stored in a dictionary, it would have to be wrapped in an NSNumber, again being treated as a true value.

    See also the Objective-C Literals spec and NSDictionary Class Reference.

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

Sidebar

Related Questions

After json parsing i get the dictionary values like this way NSDictionary* json =
I am doing some json parsing in a bash script: curl http://myurl.com/get.json | sed
I am having trouble parsing my JSON which i get from javascript. The format
From a previous question on Stackoverflow Iterating through/Parsing JSON Object via JavaScript .... My
I've a app that lives of making HTTP GET calls, and parsing the JSON
I am parsing a JSON file. After getting the NSDictionary, I parse the objects
I am parsing some JSON values. I have a NSDictionary and for a certain
I'm getting a json from server. I can parse only one JSON at time.
When parsing json service , it works fine for first time , but during
I am using SBJson framework (also known as json-framework) for the iOS. When parsing

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.