QJsonValue ClassThe QJsonValue class encapsulates a value in JSON. More... #include <QJsonValue> Note: All functions in this class are reentrant. This class was introduced in Qt 5.0. Public Types
Public Functions
Static Public Members
Detailed DescriptionThe QJsonValue class encapsulates a value in JSON. A value in JSON can be one of 6 basic types: JSON is a format to store structured data. It has 6 basic data types:
A value can represent any of the above data types. In addition, QJsonValue has one special flag to represent undefined values. This can be queried with isUndefined(). The type of the value can be queried with type() or accessors like isBool(), isString(), and so on. Likewise, the value can be converted to the type stored in it using the toBool(), toString() and so on. Values are strictly typed internally and contrary to QVariant will not attempt to do any implicit type conversions. This implies that converting to a type that is not stored in the value will return a default constructed return value. Member Type Documentation
|
Constant | Value | Description |
---|---|---|
QJsonValue::Null | 0x0 | A Null value |
QJsonValue::Bool | 0x1 | A boolean value. Use toBool() to convert to a bool. |
QJsonValue::Double | 0x2 | A double. Use toDouble() to convert to a double. |
QJsonValue::String | 0x3 | A string. Use toString() to convert to a QString. |
QJsonValue::Array | 0x4 | An array. Use toArray() to convert to a QJsonArray. |
QJsonValue::Object | 0x5 | An object. Use toObject() to convert to a QJsonObject. |
QJsonValue::Undefined | 0x80 | The value is undefined. This is usually returned as an error condition, when trying to read an out of bounds value in an array or a non existant key in an object. |
Creates a QJsonValue of type type.
The default is to create a Null value.
Creates a value of type Bool, with value b.
Creates a value of type Double, with value n.
Creates a value of type String, with value s.
Creates a value of type String, with value s.
Creates a value of type Array, with value a.
Creates a value of type Object, with value o.
Creates a copy of other.
This is an overloaded function.
Creates a value of type Double, with value n.
Destroys the value.
Converts variant to a QJsonValue and returns it.
The conversion will convert QVariant types as follows:
For all other QVariant types a conversion to a QString will be attempted. If the returned string is empty, a Null QJsonValue will be stored, otherwise a String value using the returned QString.
See also toVariant().
Converts the value to an array and returns it.
If type() is not Array, the defaultValue will be returned.
This is an overloaded function.
Converts the value to an array and returns it.
If type() is not Array, a QJsonArray() will be returned.
Converts the value to a bool and returns it.
If type() is not bool, the defaultValue will be returned.
Converts the value to a double and returns it.
If type() is not Double, the defaultValue will be returned.
Converts the value to an object and returns it.
If type() is not Object, the defaultValue will be returned.
This is an overloaded function.
Converts the value to an object and returns it.
If type() is not Object, the QJsonObject() will be returned.
Converts the value to a QString and returns it.
If type() is not String, the defaultValue will be returned.
Converts the value to a QVariant.
The QJsonValue types will be converted as follows:
Constant | Value | Description |
---|---|---|
QJsonValue::Null | ? | QVariant() |
QJsonValue::Bool | ? | QVariant::Bool(obsolete) |
QJsonValue::Double | ? | QVariant::Double(obsolete) |
QJsonValue::String | ? | QVariant::String(obsolete) |
QJsonValue::Array | ? | QVariantList |
QJsonValue::Object | ? | QVariantMap |
QJsonValue::Undefined | ? | QVariant() |
See also fromVariant().
Returns the type of the value.
See also QJsonValue::Type.
Returns true if the value is not equal to other.
Assigns the value stored in other to this object.
Returns true if the value is equal to other.