Jsonobject is judged null in Java

Source: Internet
Author: User

There are currently two types of packages found. Two different JSON packages. The first case is that the JSON package is the Json-lib package is Net.sf.json

How to tell if Jsonobject returns a string null or a null value.

Research source Discovery. There is a piece of code in Jsonobject that is when it encounters null in the JSON string. Returns Jsonnull. So when you differentiate null: jsonobject Jo = Jsonobject.fromobject ("{a:null,b:\" null \ "}"), Object o = Jo.get ("a"), if (o instanceof jsonnull) {System.out.println ("is empty null");} Else{system.out.println ("is String null");} o = Jo.get ("b"), if (o instanceof jsonnull) {System.out.println ("is empty null");} Else{system.out.println ("is String null");} The result of the input is the second case: Org.json's package Jsonobject Jo = new Jsonobject (("{\" a\ ": \" null\ ", \" b\ ": null}")); if (Jo.get ("a") instanceof String) {System.out.println ("A is String null");} Else{system.out.println ("A is empty null"); if (Jo.get ("B") instanceof string) {System.out.println ("A is String null");} Else{system.out.println ("A is empty null"); System.out.println (Jo.get ("B"). GetClass ()); It was discovered at this time. Null returned is a null value that is jsonobject.null two different packages

Jsonobject is judged null in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.