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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:28:42+00:00 2026-05-28T05:28:42+00:00

I am making calls to a server which can return key-value mappings in the

  • 0

I am making calls to a server which can return key-value mappings in the following format:

{...
 "mykey":null
...}

I am able to create a JSONObject instance from the above (using the JSONObject(String json) constructor) but am not sure how to determine whether this JSONObject instance has a mapping for “mykey” and that the value of the mapping is null? Would the following check do it…

myJSONObject.has("mykey") && !myJSONObject.isNull("mykey")

… or is there a better way? In particular, I am confused as to whether the JSONObject.NULL object means the same thing as null?

In addition: as well as getting mappings of keys whose value can be null, I need to create JSONObject instances that map null to keys. Would…

myJSONObject.put("mykey", JSONObject.NULL);

… do the job, or is there another way I should be doing 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-28T05:28:42+00:00Added an answer on May 28, 2026 at 5:28 am

    If you’re using the built-in Android JSON library, then you’re actually using the (quite capable) libraries from org.json.

    https://github.com/douglascrockford/JSON-java

    If that’s the case, we can just grep the code to see most of the answers here.

    In particular, I am confused as to whether the JSONObject.NULL object means the same thing as null?

    This should hopefully help:

    /**
     * JSONObject.NULL is equivalent to the value that JavaScript calls null,
     * whilst Java's null is equivalent to the value that JavaScript calls
     * undefined.
     */
     private static final class Null {
    
        /**
         * There is only intended to be a single instance of the NULL object,
         * so the clone method returns itself.
         * @return     NULL.
         */
        protected final Object clone() {
            return this;
        }
    
        /**
         * A Null object is equal to the null value and to itself.
         * @param object    An object to test for nullness.
         * @return true if the object parameter is the JSONObject.NULL object
         *  or null.
         */
        public boolean equals(Object object) {
            return object == null || object == this;
        }
    
        /**
         * Get the "null" string value.
         * @return The string "null".
         */
        public String toString() {
            return "null";
        }
    }
    
    /**
     * It is sometimes more convenient and less ambiguous to have a
     * <code>NULL</code> object than to use Java's <code>null</code> value.
     * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>.
     * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>.
     */
    public static final Object NULL = new Null();
    

    Part 2:

    am not sure how to determine whether this JSONObject instance has a
    mapping for “mykey” and that the value of the mapping is null? Would
    the following check do it…

    myJSONObject.has("mykey") && !myJSONObject.isNull("mykey")
    

    Yep – that seems to be about as good a method as any. In particular, you want to check for null using the isNull method, as JSONObject defines it’s own NULL object (see above).

    In addition: as well as getting mappings of keys whose value can be
    null, I need to create JSONObject instances that map null to keys.
    Would…

    myJSONObject.put(“mykey”, JSONObject.NULL); … do the job, or is
    there another way I should be doing this?

    That’s exactly how you want to do it – in particular, using JSONObject.NULL rather than java’s null (see above again).

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

Sidebar

Related Questions

I'm making AJAX calls to a server that sometimes return unparseable JSON. The server
I'm making FQL calls using the following url and then making a curl call.
I need to create a django web portal in which users can select and
When making async WCF service calls, the service is able (and must) execute the
I have a Django server which handles requests to a URL which will return
I'm looking for a code sample which illustrates making cross-threaded COM calls in an
I am making a call to a server which returns a JSON encoded object.
I'm working on an Android application which can make internet phone calls. I got
We're making some calls to some very simple JSON web services in .NET CF
i am making ajax calls with jquery like this http://pastie.org/860837 and sometimes i get

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.