diff --git a/API-Reference.md b/API-Reference.md index dcc129b..e0d84d1 100644 --- a/API-Reference.md +++ b/API-Reference.md @@ -34,7 +34,7 @@ JsonArray& array2 = jsonBuffer.parseArray(json); ##### Description -Adds a value to end of the array. +Adds a value to the end of the array. ##### Signatures @@ -130,7 +130,7 @@ unsigned short get (size_t index) const; The value at the specified index. This can be a `JsonVariant` or a value of type T. The template version of `get()` returns a value of the specified type. -In case of an error (index out of range or incompatible type), the default value of the type `T` is returned. +In the case of an error (index out of range or incompatible type), the default value of the type `T` is returned. ##### Example @@ -172,18 +172,18 @@ size_t measureLength() const Gets the length of string produced by `JsonArray::prettyPrintTo()`. -##### Return value - -The number of characters in the JSON string that would be generated by `JsonArray::prettyPrintTo()`. - -It doesn't include the zero-terminator. - ##### Signature ```c++ size_t measurePrettyLength() const ``` +##### Return value + +The number of characters in the JSON string that would be generated by `JsonArray::prettyPrintTo()`. + +It doesn't include the zero-terminator. + ### JsonArray::operator[] @@ -1183,40 +1183,129 @@ Serial.println(object.success()); // false ``` -:construction: - -:construction: Below this line, the writing is still in progress... - -:construction: ## JsonVariant -A variant that can be a any value serializable to a JSON value. - It can be set to: - - a boolean - - a char, short, int or a long (signed or unsigned) - - a string (const char*) - - a reference to a JsonArray or JsonObject -#### JsonVariant::get() +A variable that can hold different type of values: + +* a boolean +* a char, short, int or a long (signed or unsigned) +* a string (const char*) +* a reference to a JsonArray or JsonObject + +A `JsonVariant` can be any of theses types at a time, but can only hold one value. +Its type can change at run time. + + +### JsonVariant::as() + ##### Description + +Get the value of the specified type. + ##### Signatures -##### Arguments + +```c++ +bool as() const; + +float as() const; +double as() const; + +signed char as() const; +unsigned char as() const; +signed int as() const; +unsigned int as() const; +signed short as() const; +unsigned short as() const; +signed long as() const; +unsigned long as() const; +unsigned long long as() const; // <- may require ARDUINOJSON_USE_LONG_LONG +signed long long as() const; // <- may require ARDUINOJSON_USE_LONG_LONG +signed __int64 as() const; // <- may require ARDUINOJSON_USE_INT64 +unsigned __int64 as() const; // <- may require ARDUINOJSON_USE_INT64 + +const char* as() const; +const char* as() const; +String as() const; // <- causes duplication of the string + +JsonArray& as() const; +JsonArray& as() const; +JsonArray& as() const; +JsonObject& as() const; +JsonObject& as() const; +JsonObject& as() const; +``` + ##### Return value + +The value of the specified type or a default value if the `JsonVariant` is not compatible with the specified type. + +The default value is: + +* `0` for numerical types +* `NULL` for `const char*` +* `JsonArray::invalid()` for `JsonArray&` +* `JsonObject::invalid()` for `JsonObject&` + ##### Example -#### JsonVariant::is() +```c++ +JsonVariant variant = 42; +int i = variant.as(); // <- i == 42 +double d = variant.as(); // <- d == 42.0 +const char* s = variant.as(); // <- s == NULL +``` + + +### JsonVariant::is() + ##### Description + +Test if the variant is currently holding a value of the specified type. + ##### Signatures -##### Arguments + +```c++ +bool is() const; + +bool is() const; +bool is() const; + +bool is() const; +bool is() const; +bool is() const; +bool is() const; +bool is() const; +bool is() const; +bool is() const; +bool is() const; +bool is() const; // <- may require ARDUINOJSON_USE_LONG_LONG +bool is() const; // <- may require ARDUINOJSON_USE_LONG_LONG +bool is() const; // <- may require ARDUINOJSON_USE_INT64 +bool is() const; // <- may require ARDUINOJSON_USE_INT64 + +bool is() const; +bool is() const; + +bool is() const; +bool is() const; +bool is() const; +bool is() const; +bool is() const; +bool is() const; +``` + ##### Return value + +* `true` if the variant is currently holding a value of the specified type, +* `false` if not + ##### Example -#### JsonVariant::set() -##### Description -##### Signatures -##### Arguments -##### Return value -##### Example - -#### Implicit conversions \ No newline at end of file +```c++ +JsonVariant variant = 42; +bool i = variant.is(); // <- i == true +bool d = variant.is(); // <- d == false +bool s = variant.is(); // <- s == false +``` \ No newline at end of file