我们可以通过以下代码来实现对JSONObject是否为空的判断: importorg.json.JSONObject;publicclassJsonUtil{publicstaticbooleanisJsonObjectEmpty(JSONObjectjsonObject){// 判断JSONObject是否为nullif(jsonObject==null){returntrue;// 空}// 判断JSONObject是否没有任何键值对returnjsonObject.isEmpty();}publicstaticvoi...
我们可以通过JSONObject的length()方法来判断JSONObject中是否有键值对。如果长度为0,则表示JSONObject为空。 下面是一个示例代码: importorg.json.JSONObject;publicclassMain{publicstaticvoidmain(String[]args){JSONObjectjson=newJSONObject();// 判断JSONObject是否为空if(json.length()==0){System.out.println...
如图所示的json,取出bookingData判断为null的问题 if(jsonObject.get("bookingData") == null || "null".equals(jsonObject.get("bookingData")) || isEmpty等判断都为true) 直接getJsonObject ,由于bookingData为null会报错 用jsonObject.isNull(“bookingData”)可正确判断; 赶项目,匆忙记录,请忽略格式混乱...