I am using HttpURLConnection
to retrieve a JSON string. It looks like this:
{
"status":"ok",
"testSuites":[
{
// possibly one object in here
}
]
}
I want to know if the array is empty. There will be at most one object in the array. I tried the following:
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse(json).getAsJsonObject();
JsonArray testSuites = obj.getAsJsonArray("testSuites");
and then checked if testSuites
was null
, but that doesn't work, because it's not null
. But it is empty!
I figured it out. You can use the size()
method to determine the number of elements in the array.
if (testSuites.size() == 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With