JsonArray::isNull()
Description
JsonArray::isNull()
tells whether the JsonArray
points to an array or not.
You can use this function to:
- check if the array was successfully parsed, or
- check if the array was successfully allocated.
As an alternative, you can use the conversion to bool
; for example, if(array)
instead of if(!array.isNull())
Signature
bool isNull() const;
Return value
JsonArray::isNull()
returns a bool
that tells if the JsonArray
points to something:
Examples
Example 1: parsing success:
StaticJsonDocument<200> doc;
deserializeJson(doc, "[1,2]");
JsonArray array = doc.as<JsonArray>();
Serial.println(array.isNull()); // false
Example 2: parsing failure:
StaticJsonDocument<200> doc;
deserializeJson(doc, "{1,2}");
JsonArray array = doc.as<JsonArray>();
Serial.println(array.isNull()); // true
Example 3: allocation success:
StaticJsonDocument<200> doc;
JsonArray array = doc.to<JsonArray>();
Serial.println(array.isNull()); // false
Example 4: allocation failure:
StaticJsonDocument<1> doc;
JsonArray array = doc.to<JsonArray>();
Serial.println(array.isNull()); // true