Java 断言JSON中的值为null

Java 断言JSON中的值为null,java,json,Java,Json,我有一个json,我希望它的值在映射中向下,除非该值为NULL,否则我只需要一个空字符串 我尝试了几种不同的观点来说明我从json中得到的值是什么,但它们似乎都不能说明值是空的 if (!isNull(json.get("id"))) { orderDataMap.put("id", json.get("id")); } else { orderDataMap.put("id", ""); } if (!isNull(json.get("sr"))) { orderDataM

我有一个json,我希望它的值在映射中向下,除非该值为NULL,否则我只需要一个空字符串

我尝试了几种不同的观点来说明我从json中得到的值是什么,但它们似乎都不能说明值是空的

if (!isNull(json.get("id"))) {
   orderDataMap.put("id", json.get("id"));
} else {
   orderDataMap.put("id", "");
}

if (!isNull(json.get("sr"))) {
   orderDataMap.put("sr", json.get("sr"));
} else {
   orderDataMap.put("sr", "");
}
if (!isNull(json.get("systemOrderId"))) {
   orderDataMap.put("systemOrderId", json.get("systemOrderId"));
} else {
   orderDataMap.put("systemOrderId", "");
}
在if语句中,我还尝试使用
json.get(“id”)!=NULL
以及json.get(“id”).equals(NULL)

以下是调试时的外观:

使用JSONObject.isNull检查值是否不存在或为null

if (json.isNull("id")) {
    orderDataMap.put("id", json.get("id"));
    } else {
    orderDataMap.put("id", "");
}

请检查:谢谢,这是解决方案