Tests if the value at specified index has the type T
.
bool is<bool> (size_t index) const;
bool is<const char*> (size_t index) const;
bool is<char*> (size_t index) const;
bool is<double> (size_t index) const;
bool is<float> (size_t index) const;
bool is<signed char> (size_t index) const;
bool is<signed int> (size_t index) const;
bool is<signed long> (size_t index) const;
bool is<signed short> (size_t index) const;
bool is<unsigned char> (size_t index) const;
bool is<unsigned int> (size_t index) const;
bool is<unsigned long> (size_t index) const;
bool is<unsigned short> (size_t index) const;
bool is<signed long long> (size_t index) const; // <- may require ARDUINOJSON_USE_LONG_LONG
bool is<unsigned long long>(size_t index) const; // <- may require ARDUINOJSON_USE_LONG_LONG
bool is<JsonArray> (size_t index) const;
bool is<JsonObject> (size_t index) const;
Arguments
index
: the index of the value in the array.
T
: the type to test.
true
if value at specified index matches the type T
,false
if notDifferent C++ types can store the same JSON value, so is<T>()
can return true
for several T
s. For example, is<float>()
always returns the same value as is<double>()
.
The table below gives the correspondence between the JSON type and the C++ types:
JSON typeT
Floating point float
, double
Integer int
, short
, long
, long long
String const char*
, char*
Boolean bool
Array JsonArray
Object JsonObject
Caution: is<float>()
and is<double>()
return true
for integers too.
char json[] = "[\"pi\",3.14]";
StaticJsonBuffer<256> jsonBuffer;
JsonArray& array = jsonBuffer.parseArray(json);
bool firstIsString = array.is<char*>(0); // <- true
bool secondIsFloat = array.is<float>(1); // <- true
// but we could also use JsonVariant.is<T>(), like that:
firstIsString = array[0].is<char*>(); // <- true
secondIsFloat = array[1].is<float>(); // <- 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