How to test if JSON object is empty in Java

前端 未结 15 2391

The JSON object I\'m receiving looks like this:

[{\"foo1\":\"bar1\", \"foo2\":\"bar2\", \"problemkey\": \"problemvalue\"}]

What I\'m trying

15条回答
  •  执笔经年
    2020-12-14 00:37

    I have added isEmpty() methods on JSONObject and JSONArray()

     //on JSONObject 
     public Boolean isEmpty(){         
         return !this.keys().hasNext();
     }
    

    ...

    //on JSONArray
    public Boolean isEmpty(){
        return this.length()==0;        
    }
    

    you can get it here https://github.com/kommradHomer/JSON-java

提交回复
热议问题