Java 正在检查JSON对象中特定于退出的值
我曾读到过有关这件事的报道。但这个问题并不满足于我的问题。我用于从数据库中检索数据 我有一个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
{"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");
}