How to test if JSON object is empty in Java

前端 未结 15 2404

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

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

What I\'m trying

15条回答
  •  庸人自扰
    2020-12-14 00:36

    Object getResult = obj.get("dps"); 
    if (getResult != null && getResult instanceof java.util.Map && (java.util.Map)getResult.isEmpty()) {
        handleEmptyDps(); 
    } 
    else {
        handleResult(getResult); 
    }
    

提交回复
热议问题