Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在检查JSON对象中特定于退出的值_Java_Json_Dom - Fatal编程技术网

Java 正在检查JSON对象中特定于退出的值

Java 正在检查JSON对象中特定于退出的值,java,json,dom,Java,Json,Dom,我曾读到过有关这件事的报道。但这个问题并不满足于我的问题。我用于从数据库中检索数据 我有一个JSON对象,就像 {"a":"data", "b":"", "c":null, "d":2} 我测试了这个JSON中的e值 if (json.get("e") == null) { System.err.println("found in first case."); } else if (json

我曾读到过有关这件事的报道。但这个问题并不满足于我的问题。我用于从数据库中检索数据

我有一个JSON对象,就像

{"a":"data", "b":"", "c":null, "d":2}
我测试了这个JSON中的e

            if (json.get("e") == null) {
                System.err.println("found in first case.");
            }
            else if (json.get("e").isNull()) {
                System.err.println("found in second case.");
            }
            else {
                System.err.println("All were skipped !");
            }

但是结果并不像我预期的那样(它总是转到其他情况下)。我还希望避免空指针异常。我该如何实现它呢?

现在我找到了解决方案

    if(json.keySet().contains("e")) {
        System.out.println("BOOM");
    }
    else {
        System.out.println("Not contain");
    }