CopperSpice API
1.9.2
|
Encapsulates a value in JSON. More...
Public Types | |
enum | Type |
Public Methods | |
QJsonValue (bool b) | |
QJsonValue (const QJsonValue &other) | |
QJsonValue (double n) | |
QJsonValue (int n) | |
QJsonValue (qint64 n) | |
QJsonValue (QJsonArray array) | |
QJsonValue (QJsonObject object) | |
QJsonValue (QString str) | |
QJsonValue (Type type=Null) | |
~QJsonValue () | |
bool | isArray () const |
bool | isBool () const |
bool | isDouble () const |
bool | isNull () const |
bool | isObject () const |
bool | isString () const |
bool | isUndefined () const |
bool | operator!= (const QJsonValue &other) const |
QJsonValue & | operator= (const QJsonValue &other) |
bool | operator== (const QJsonValue &other) const |
QJsonArray | toArray () const |
QJsonArray | toArray (const QJsonArray &defaultValue) const |
bool | toBool (bool defaultValue=false) const |
double | toDouble (double defaultValue=0) const |
int | toInt (int defaultValue=0) const |
QJsonObject | toObject () const |
QJsonObject | toObject (const QJsonObject &defaultValue) const |
QString | toString (const QString &defaultValue=QString ()) const |
QVariant | toVariant () const |
Type | type () const |
Static Public Methods | |
static QJsonValue | fromVariant (const QVariant &variant) |
The QJsonValue class encapsulates the value type available in a JSON format. A value can only be one of the data types shown below.
There is one extra QJsonValue which is used to represent undefined values.
The data type of a value can be queried using type() or with the methods like isBool(), isDouble(), isString(), isArray(), and isObject(). The method isUndefined() is used to query if the data type is Type::Undefined.
The value stored in a QJsonValue can be retrieved by using toBool(), toDouble(), toInt(), toString(), toArray(), and toObject().
enum QJsonValue::Type |
This enum describes the type of the JSON value.
Constant | Value | Description |
---|---|---|
QJsonValue::Null | 0x0 | |
QJsonValue::Bool | 0x1 | toBool() to convert to a bool |
QJsonValue::Double | 0x2 | toDouble() to convert to a double |
QJsonValue::String | 0x3 | toString() to convert to a QString |
QJsonValue::Array | 0x4 | toArray() to convert to a QJsonArray |
QJsonValue::Object | 0x5 | toObject() to convert to a QJsonObject |
QJsonValue::Undefined | 0x80 | Usually the result of an error when trying to read an out of bounds value in an array or a non existent key in an object |
QJsonValue::QJsonValue | ( | Type | type = Null | ) |
Creates a QJsonValue of the given type. The default is to create a null value.
QJsonValue::QJsonValue | ( | bool | b | ) |
Creates a value of type bool with value b.
QJsonValue::QJsonValue | ( | double | n | ) |
Creates a value of type double with value n.
QJsonValue::QJsonValue | ( | int | n | ) |
Creates a value of type double with value n.
QJsonValue::QJsonValue | ( | qint64 | n | ) |
Creates a value of type double, with value n.
QJsonValue::QJsonValue | ( | QString | str | ) |
Creates a value of type string with value str.
QJsonValue::QJsonValue | ( | QJsonArray | array | ) |
Creates a value of type array with value array.
QJsonValue::QJsonValue | ( | QJsonObject | object | ) |
Creates a value of type object with value object.
QJsonValue::QJsonValue | ( | const QJsonValue & | other | ) |
Creates a copy of other.
QJsonValue::~QJsonValue | ( | ) |
Destroys the value.
|
static |
Converts variant to a QJsonValue and returns the converted value. For all other QVariant types which are not shown in the table below, a conversion to a QString will be attempted. If the returned string is empty a null QJsonValue will be returned.
Source Type | Destination Type |
---|---|
QVariant::Bool | QJsonValue::Bool |
QVariant::Int QVariant::UInt QVariant::LongLong QVariant::ULongLong QVariant::Double QVariant::Float | QJsonValue::Double |
QVariant::String | QJsonValue::String |
QVariant::StringList QVariant::List | QJsonValue::Array |
QVariant::Hash QVariant::Map | QJsonValue::Object |
|
inline |
Returns true if the value contains an array.
|
inline |
Returns true if the value contains a boolean.
|
inline |
Returns true if the value contains a double.
|
inline |
Returns true if the value is null.
|
inline |
Returns true if the value contains an object.
|
inline |
Returns true if the value contains a string.
|
inline |
Returns true if the value is undefined. This can happen in certain error cases, for example accessing a non existing key in a QJsonObject.
bool QJsonValue::operator!= | ( | const QJsonValue & | other | ) | const |
Returns true
if the value is not equal to other.
QJsonValue & QJsonValue::operator= | ( | const QJsonValue & | other | ) |
Copy assigns from other and returns a reference to this object.
bool QJsonValue::operator== | ( | const QJsonValue & | other | ) | const |
Returns true if the value is equal to other.
QJsonArray QJsonValue::toArray | ( | ) | const |
Returns the value as a QJsonArray. If the type() is not an array an empty array will be returned.
QJsonArray QJsonValue::toArray | ( | const QJsonArray & | defaultValue | ) | const |
Returns the value as a QJsonArray. If the type() is not an array the defaultValue will be returned.
bool QJsonValue::toBool | ( | bool | defaultValue = false | ) | const |
Returns the value as a bool. If the type() is not a bool the defaultValue will be returned.
double QJsonValue::toDouble | ( | double | defaultValue = 0 | ) | const |
Returns the value as a double. If the type() is not a double the defaultValue will be returned.
int QJsonValue::toInt | ( | int | defaultValue = 0 | ) | const |
Returns the value as an int. If the type() is not a double the defaultValue will be returned.
QJsonObject QJsonValue::toObject | ( | ) | const |
Returns the value as an object. If the type() is not an object an empty object will be returned.
QJsonObject QJsonValue::toObject | ( | const QJsonObject & | defaultValue | ) | const |
Returns the value as an object. If the type() is not an object the defaultValue will be returned.
Returns the value as a string. If the type() is not a string the defaultValue will be returned.
QVariant QJsonValue::toVariant | ( | ) | const |
Converts the given value to a QVariant. The QJsonValue will be converted to a QVariant of the corresponding type.
JSON Data Type | Description |
---|---|
QJsonValue::Null | Empty QVariant |
QJsonValue::Undefined | Empty QVariant |
QJsonValue::Bool | QVariant::Bool |
QJsonValue::Double | QVariant::Double |
QJsonValue::String | QString |
QJsonValue::Array | QVariantList |
QJsonValue::Object | QVariantMap |
Type QJsonValue::type | ( | ) | const |
Returns the type of the value.