Wt
4.10.4
|
A JSON value. More...
#include <Value.h>
Public Member Functions | |
Value () | |
Default construtor. | |
Value (const WString &value) | |
Creates a value from a string. | |
Value (WString &&value) | |
Creates a value from a string. | |
Value (bool value) | |
Creates a value from a boolean. | |
Value (int value) | |
Creates a value from an integer. | |
Value (long value) | |
Creates a value from a long. | |
Value (long long value) | |
Creates a value from a long long. | |
Value (double value) | |
Creates a value from a double. | |
Value (const char *value) | |
Creates a value from a const char*. | |
Value (const Array &value) | |
Creates a value from a Json::Object. | |
Value (Array &&value) | |
Creates a value from a Json::Object. | |
Value (const Object &value) | |
Creates a value from a Json::Object. | |
Value (Object &&value) | |
Creates a value from a Json::Object. | |
Value (Type type) | |
Creates a value with a given type. | |
Value (const Value &other) | |
Copy constructor. | |
Value (Value &&other) | |
Move constructor. | |
Value & | operator= (const Value &other) |
Assignment operator. | |
Value & | operator= (Value &&other) |
Move Assignment operator. | |
Value & | operator= (Object &&other) |
Move assignment operator. | |
Value & | operator= (Array &&other) |
Move assignment operator. | |
bool | operator== (const Value &other) const |
Comparison operator. | |
bool | operator!= (const Value &other) const |
Comparison operator. | |
Type | type () const |
Returns the type. | |
bool | isNull () const |
Returns whether the value is Null. | |
bool | hasType (const std::type_info &type) const |
Returns whether the value is compatible with a given C++ type. | |
operator const WString & () const | |
Extracts the string value. | |
operator std::string () const | |
Extracts the string value (UTF-8 encoded). | |
operator bool () const | |
Extracts the boolean value. | |
operator int () const | |
Extracts the integer number value. | |
operator long () const | |
Extracts the integer number value. | |
operator long long () const | |
Extracts the integer number value. | |
operator double () const | |
Extracts the floating point number value. | |
operator const Array & () const | |
Extracts the array value. | |
operator const Object & () const | |
Extracts the object value. | |
operator Array & () | |
Accesses the array value. | |
operator Object & () | |
Accesses the object value. | |
const WString & | orIfNull (const WString &v) const |
Extracts the string value, using a fallback when null. | |
std::string | orIfNull (const char *v) const |
Extracts the UTF-8 encoded string value, using a fallback when null. | |
std::string | orIfNull (const std::string &v) const |
Extracts the UTF-8 encoded string value, using a fallback when null. | |
bool | orIfNull (bool v) const |
Extracts the boolean value, using a fallback when null. | |
int | orIfNull (int v) const |
Extracts the number value, using a fallback when null. | |
long long | orIfNull (long long v) const |
Extracts the number value, using a fallback when null. | |
double | orIfNull (double v) const |
Extracts the number value, using a fallback when null. | |
const Array & | orIfNull (const Array &v) const |
Extracts the array value, using a fallback when null. | |
const Object & | orIfNull (const Object &v) const |
Extracts the object value, using a fallback when null. | |
Value | toString () const |
Converts the value to a string. | |
Value | toBool () const |
Converts the value to a boolean. | |
Value | toNumber () const |
Converts the value to a number. | |
Static Public Member Functions | |
static Type | typeOf (const std::type_info &type) |
Returns the JSON type that corresponds to a C++ type. | |
Static Public Attributes | |
static const Value | Null |
Null constant. | |
static const Value | True |
True constant. | |
static const Value | False |
False constant. | |
A JSON value.
This class represents a JSON value, which may be:
Wt::Json::Value::Value | ( | ) |
Default construtor.
This creates a Null value.
Creates a value from a string.
This creates a Json::Type::String value.
Wt::Json::Value::Value | ( | WString && | value | ) |
Creates a value from a string.
This creates a Json::Type::String value.
Wt::Json::Value::Value | ( | bool | value | ) |
Creates a value from a boolean.
This creates a Json::Type::Bool value.
Wt::Json::Value::Value | ( | int | value | ) |
Creates a value from an integer.
This creates a Json::Type::Number value.
Wt::Json::Value::Value | ( | long | value | ) |
Creates a value from a long.
This creates a Json::Type::Number value.
Creates a value from a long long.
This creates a Json::Type::Number value.
Wt::Json::Value::Value | ( | double | value | ) |
Creates a value from a double.
This creates a Json::Type::Number value.
Creates a value from a const char*.
This creates a Json::StringType value.
This constructor first converts const char* to WString using WString(const char *)
Creates a value from a Json::Object.
This creates a Json::ArrayType value.
Wt::Json::Value::Value | ( | Array && | value | ) |
Creates a value from a Json::Object.
This creates a Json::ArrayType value.
Creates a value from a Json::Object.
This creates a Json::ObjectType value.
Wt::Json::Value::Value | ( | Object && | value | ) |
Creates a value from a Json::Object.
This creates a Json::ObjectType value.
Wt::Json::Value::Value | ( | Type | type | ) |
Creates a value with a given type.
This creates a value of the given type, using a default constructed value of that type:
Returns whether the value is compatible with a given C++ type.
This returns whether the value type can be contained in the given C++ type, i.e. when a casting operation will not fail throwing a TypeException.
bool Wt::Json::Value::isNull | ( | ) | const |
Returns whether the value is Null.
This returns true
when the type is Json::Type::Null.
Wt::Json::Value::operator Array & | ( | ) |
Accesses the array value.
This returns the value of a array JSON value.
Use this method to modify the contained array in-place.
For example:
TypeException | if the value type is not Json::Type::Array |
Wt::Json::Value::operator bool | ( | ) | const |
Extracts the boolean value.
This returns the value of a boolean JSON value.
For example:
To coerce a value of another type to a boolean use toBool() first. To provide a fallback in case the value is null or could not be coerced to a boolean, use orIfNull().
For example, the following code does not throw exceptions:
TypeException | if the value type is not Json::Type::Bool |
Extracts the array value.
This returns the value of a array JSON value.
For example:
To provide a fallback in case the value is null, use orIfNull().
TypeException | if the value type is not Json::Type::Array |
Extracts the object value.
This returns the value of a object JSON value.
For example:
To provide a fallback in case the value is null, use orIfNull().
TypeException | if the value type is not Json::Type::Object |
Extracts the string value.
This returns the value of a string JSON value.
For example:
To coerce a value of another type to a string use toString() first. To provide a fallback in case the value is null or could not be coerced to a string, use orIfNull().
For example, the following code does not throw exceptions:
TypeException | if the value type is not Json::Type::String |
Wt::Json::Value::operator double | ( | ) | const |
Extracts the floating point number value.
This returns the value of a number JSON value.
For example:
To coerce a value of another type to a number use toNumber() first. To provide a fallback in case the value is null or could not be coerced to a number, use orIfNull().
For example, the following code does not throw exceptions:
TypeException | if the value type is not Json::Type::Number |
Wt::Json::Value::operator int | ( | ) | const |
Extracts the integer number value.
This returns the value of a number JSON value.
For example:
To coerce a value of another type to a number use toNumber() first. To provide a fallback in case the value is null or could not be coerced to a number, use orIfNull().
For example, the following code does not throw exceptions:
TypeException | if the value type is not Json::Type::Number |
Wt::Json::Value::operator long | ( | ) | const |
Extracts the integer number value.
This returns the value of a number JSON value.
For example:
To coerce a value of another type to a number use toNumber() first. To provide a fallback in case the value is null or could not be coerced to a number, use orIfNull().
For example, the following code does not throw exceptions:
TypeException | if the value type is not Json::Type::Number |
Extracts the integer number value.
This returns the value of a number JSON value.
For example:
To coerce a value of another type to a number use toNumber() first. To provide a fallback in case the value is null or could not be coerced to a number, use orIfNull().
For example, the following code does not throw exceptions:
TypeException | if the value type is not Json::Type::Number |
Wt::Json::Value::operator Object & | ( | ) |
Accesses the object value.
This returns the value of a object JSON value.
Use this method to modify the contained object in-place.
For example:
TypeException | if the value type is not Json::Type::Object |
Wt::Json::Value::operator std::string | ( | ) | const |
Extracts the string value (UTF-8 encoded).
This returns the value of a string JSON value.
For example:
To coerce a value of another type to a string use toString() first. To provide a fallback in case the value is null or could not be coerced to a string, use orIfNull().
For example, the following code does not throw exceptions:
TypeException | if the value type is not Json::Type::String |
Comparison operator.
Returns whether two values have a different type or value.
Assignment operator.
As a result of an assignment, both value and type are set to the value and type of the other
value.
Move Assignment operator.
As a result of an assignment, both value and type are set to the value and type of the other
value.
Comparison operator.
Returns whether two values have the same type and value.
Extracts the boolean value, using a fallback when null.
This is similar to the boolean cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::Bool |
Extracts the array value, using a fallback when null.
This is similar to the Array cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::Array |
Extracts the UTF-8 encoded string value, using a fallback when null.
This is similar to the string cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::String |
Extracts the object value, using a fallback when null.
This is similar to the Object cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::Object |
std::string Wt::Json::Value::orIfNull | ( | const std::string & | v | ) | const |
Extracts the UTF-8 encoded string value, using a fallback when null.
This is similar to the string cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::String |
Extracts the string value, using a fallback when null.
This is similar to the string cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::String |
Extracts the number value, using a fallback when null.
This is similar to the double cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::Number |
Extracts the number value, using a fallback when null.
This is similar to the int cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::Number |
Extracts the number value, using a fallback when null.
This is similar to the long long cast operator, but this method returns a fallback when the value is null instead of throwing an exception.
TypeException | if the value is not null and has a type other than Json::Type::Number |
Value Wt::Json::Value::toBool | ( | ) | const |
Converts the value to a boolean.
A string value of "true" or "false" is interpreted as a boolean. Otherwise, Null is returned.
Value Wt::Json::Value::toNumber | ( | ) | const |
Converts the value to a number.
A string value is lexically casted to a number. If this fails, or for a boolean, array or object type, Null is returned.
Value Wt::Json::Value::toString | ( | ) | const |
Converts the value to a string.
The value is lexically casted to a string. For an object or array value, this coercion is not defined and Null is returned.
WException | if the Value is a number initialized to NaN |
Type Wt::Json::Value::type | ( | ) | const |
Returns the type.
Returns the type of this value.
Returns the JSON type that corresponds to a C++ type.
This is a utility method for converting between C++ types and JSON types.
False constant.
A constant value of type Json::Type::Bool with value false
, i.e. as constructed by Json::Value(false)
Null constant.
A constant value with type Json::Type::Null, i.e. as constructed by Json::Value()
.
True constant.
A constant value of type Json::Type::Bool with value true
, i.e. as constructed by Json::Value(true)
.