JsonObject::isNull()
tests whether the JsonObject
points to an object or not.
You can use this function to:
As an alternative, you can use the conversion to bool
; for example, if(object)
instead of if(!object.isNull())
JsonObject::isNull()
returns a bool
that tells if the JsonObject
points to something:
true
if the JsonObject
is null,false
if the JsonObject
is valid and points to an object.Example 1: parsing success:
StaticJsonDocument<200> doc;
deserializeJson(doc, "{\"hello\":\"world\"}");
JsonObject object = doc.as<JsonObject>();
Serial.println(object.isNull()); // false
Example 2: parsing failure:
StaticJsonDocument<200> doc;
deserializeJson(doc, "[\"hello\",\"world\"]");
JsonObject object = doc.as<JsonObject>();
Serial.println(object.isNull()); // true
Example 3: allocation success:
StaticJsonDocument<200> doc;
JsonObject object = doc.to<JsonObject>();
Serial.println(object.isNull()); // false
Example 4: allocation failure:
StaticJsonDocument<1> doc;
JsonObject object = doc.to<JsonObject>();
Serial.println(object.isNull()); // true
See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4