Struct qt_core::QJsonValue
source · #[repr(C)]pub struct QJsonValue { /* private fields */ }
Expand description
The QJsonValue class encapsulates a value in JSON.
C++ class: QJsonValue
.
The 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:
- bool QJsonValue::Bool
- double QJsonValue::Double
- string QJsonValue::String
- array QJsonValue::Array
- object QJsonValue::Object
- null QJsonValue::Null
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.
Implementations§
source§impl QJsonValue
impl QJsonValue
sourcepub unsafe fn copy_from(
&self,
other: impl CastInto<Ref<QJsonValue>>
) -> Ref<QJsonValue>
pub unsafe fn copy_from( &self, other: impl CastInto<Ref<QJsonValue>> ) -> Ref<QJsonValue>
Assigns the value stored in other to this object.
Calls C++ function: QJsonValue& QJsonValue::operator=(const QJsonValue& other)
.
Assigns the value stored in other to this object.
sourcepub unsafe fn from_variant(
variant: impl CastInto<Ref<QVariant>>
) -> CppBox<QJsonValue>
pub unsafe fn from_variant( variant: impl CastInto<Ref<QVariant>> ) -> CppBox<QJsonValue>
Converts variant to a QJsonValue and returns it.
Calls C++ function: static QJsonValue QJsonValue::fromVariant(const QVariant& variant)
.
Converts variant to a QJsonValue and returns it.
The conversion will convert QVariant types as follows:
Source type | Destination type |
---|---|
| QJsonValue::Null |
QJsonValue::Bool | |
QJsonValue::Double | |
QJsonValue::String | |
QJsonValue::Array | |
QJsonValue::Object |
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().
sourcepub unsafe fn index_q_string(
&self,
key: impl CastInto<Ref<QString>>
) -> CppBox<QJsonValue>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn index_q_string( &self, key: impl CastInto<Ref<QString>> ) -> CppBox<QJsonValue>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a QJsonValue representing the value for the key key.
Calls C++ function: QJsonValue QJsonValue::operator[](const QString& key) const
.
Returns a QJsonValue representing the value for the key key.
Equivalent to calling toObject().value(key).
The returned QJsonValue is QJsonValue::Undefined if the key does not exist, or if isObject() is false.
This function was introduced in Qt 5.10.
See also QJsonValue, QJsonValue::isUndefined(), and QJsonObject.
sourcepub unsafe fn index_q_latin1_string(
&self,
key: impl CastInto<Ref<QLatin1String>>
) -> CppBox<QJsonValue>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn index_q_latin1_string( &self, key: impl CastInto<Ref<QLatin1String>> ) -> CppBox<QJsonValue>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.This is an overloaded function.
Calls C++ function: QJsonValue QJsonValue::operator[](QLatin1String key) const
.
This is an overloaded function.
This function was introduced in Qt 5.10.
sourcepub unsafe fn index_int(&self, i: c_int) -> CppBox<QJsonValue>
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn index_int(&self, i: c_int) -> CppBox<QJsonValue>
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns a QJsonValue representing the value for index i.
Calls C++ function: QJsonValue QJsonValue::operator[](int i) const
.
Returns a QJsonValue representing the value for index i.
Equivalent to calling toArray().at(i).
The returned QJsonValue is QJsonValue::Undefined, if i is out of bounds, or if isArray() is false.
This function was introduced in Qt 5.10.
See also QJsonValue, QJsonValue::isUndefined(), and QJsonArray.
sourcepub unsafe fn index_q_string_view(
&self,
key: impl CastInto<Ref<QStringView>>
) -> CppBox<QJsonValue>
Available on cpp_lib_version="5.14.0"
only.
pub unsafe fn index_q_string_view( &self, key: impl CastInto<Ref<QStringView>> ) -> CppBox<QJsonValue>
cpp_lib_version="5.14.0"
only.This is an overloaded function.
Calls C++ function: QJsonValue QJsonValue::operator[](QStringView key) const
.
This is an overloaded function.
This function was introduced in Qt 5.14.
sourcepub unsafe fn is_array(&self) -> bool
pub unsafe fn is_array(&self) -> bool
Returns true
if the value contains an array.
Calls C++ function: bool QJsonValue::isArray() const
.
Returns true
if the value contains an array.
See also toArray().
sourcepub unsafe fn is_bool(&self) -> bool
pub unsafe fn is_bool(&self) -> bool
Returns true
if the value contains a boolean.
Calls C++ function: bool QJsonValue::isBool() const
.
Returns true
if the value contains a boolean.
See also toBool().
sourcepub unsafe fn is_double(&self) -> bool
pub unsafe fn is_double(&self) -> bool
Returns true
if the value contains a double.
Calls C++ function: bool QJsonValue::isDouble() const
.
Returns true
if the value contains a double.
See also toDouble().
sourcepub unsafe fn is_null(&self) -> bool
pub unsafe fn is_null(&self) -> bool
Returns true
if the value is null.
Calls C++ function: bool QJsonValue::isNull() const
.
Returns true
if the value is null.
sourcepub unsafe fn is_object(&self) -> bool
pub unsafe fn is_object(&self) -> bool
Returns true
if the value contains an object.
Calls C++ function: bool QJsonValue::isObject() const
.
Returns true
if the value contains an object.
See also toObject().
sourcepub unsafe fn is_string(&self) -> bool
pub unsafe fn is_string(&self) -> bool
Returns true
if the value contains a string.
Calls C++ function: bool QJsonValue::isString() const
.
Returns true
if the value contains a string.
See also toString().
sourcepub unsafe fn is_undefined(&self) -> bool
pub unsafe fn is_undefined(&self) -> bool
Returns true
if the value is undefined. This can happen in certain error cases as e.g. accessing a non existing key in a QJsonObject.
Calls C++ function: bool QJsonValue::isUndefined() const
.
Returns true
if the value is undefined. This can happen in certain error cases as e.g. accessing a non existing key in a QJsonObject.
sourcepub unsafe fn from_type(arg1: Type) -> CppBox<QJsonValue>
pub unsafe fn from_type(arg1: Type) -> CppBox<QJsonValue>
Creates a QJsonValue of type type.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(QJsonValue::Type arg1 = …)
.
Creates a QJsonValue of type type.
The default is to create a Null value.
sourcepub unsafe fn from_bool(b: bool) -> CppBox<QJsonValue>
pub unsafe fn from_bool(b: bool) -> CppBox<QJsonValue>
Creates a value of type Bool, with value b.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(bool b)
.
Creates a value of type Bool, with value b.
sourcepub unsafe fn from_double(n: c_double) -> CppBox<QJsonValue>
pub unsafe fn from_double(n: c_double) -> CppBox<QJsonValue>
Creates a value of type Double, with value n.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(double n)
.
Creates a value of type Double, with value n.
sourcepub unsafe fn from_int(n: c_int) -> CppBox<QJsonValue>
pub unsafe fn from_int(n: c_int) -> CppBox<QJsonValue>
This is an overloaded function.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(int n)
.
This is an overloaded function.
Creates a value of type Double, with value n.
sourcepub unsafe fn from_i64(n: i64) -> CppBox<QJsonValue>
pub unsafe fn from_i64(n: i64) -> CppBox<QJsonValue>
This is an overloaded function.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(qint64 n)
.
This is an overloaded function.
Creates a value of type Double, with value n. NOTE: the integer limits for IEEE 754 double precision data is 2^53 (-9007199254740992 to +9007199254740992). If you pass in values outside this range expect a loss of precision to occur.
sourcepub unsafe fn from_q_string(
s: impl CastInto<Ref<QString>>
) -> CppBox<QJsonValue>
pub unsafe fn from_q_string( s: impl CastInto<Ref<QString>> ) -> CppBox<QJsonValue>
Creates a value of type String, with value s.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(const QString& s)
.
Creates a value of type String, with value s.
sourcepub unsafe fn from_q_latin1_string(
s: impl CastInto<Ref<QLatin1String>>
) -> CppBox<QJsonValue>
pub unsafe fn from_q_latin1_string( s: impl CastInto<Ref<QLatin1String>> ) -> CppBox<QJsonValue>
Creates a value of type String, with value s.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(QLatin1String s)
.
Creates a value of type String, with value s.
sourcepub unsafe fn from_char(s: *const c_char) -> CppBox<QJsonValue>
pub unsafe fn from_char(s: *const c_char) -> CppBox<QJsonValue>
Creates a value of type String with value s, assuming UTF-8 encoding of the input.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(const char* s)
.
Creates a value of type String with value s, assuming UTF-8 encoding of the input.
You can disable this constructor by defining QT_NO_CAST_FROM_ASCII
when you compile your applications.
This function was introduced in Qt 5.3.
sourcepub unsafe fn from_q_json_array(
a: impl CastInto<Ref<QJsonArray>>
) -> CppBox<QJsonValue>
pub unsafe fn from_q_json_array( a: impl CastInto<Ref<QJsonArray>> ) -> CppBox<QJsonValue>
Creates a value of type Array, with value a.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(const QJsonArray& a)
.
Creates a value of type Array, with value a.
sourcepub unsafe fn from_q_json_object(
o: impl CastInto<Ref<QJsonObject>>
) -> CppBox<QJsonValue>
pub unsafe fn from_q_json_object( o: impl CastInto<Ref<QJsonObject>> ) -> CppBox<QJsonValue>
Creates a value of type Object, with value o.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(const QJsonObject& o)
.
Creates a value of type Object, with value o.
sourcepub unsafe fn new() -> CppBox<QJsonValue>
pub unsafe fn new() -> CppBox<QJsonValue>
The QJsonValue class encapsulates a value in JSON.
Calls C++ function: [constructor] void QJsonValue::QJsonValue()
.
The 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:
- bool QJsonValue::Bool
- double QJsonValue::Double
- string QJsonValue::String
- array QJsonValue::Array
- object QJsonValue::Object
- null QJsonValue::Null
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.
sourcepub unsafe fn new_copy(
other: impl CastInto<Ref<QJsonValue>>
) -> CppBox<QJsonValue>
pub unsafe fn new_copy( other: impl CastInto<Ref<QJsonValue>> ) -> CppBox<QJsonValue>
Creates a copy of other.
Calls C++ function: [constructor] void QJsonValue::QJsonValue(const QJsonValue& other)
.
Creates a copy of other.
sourcepub unsafe fn swap(&self, other: impl CastInto<Ref<QJsonValue>>)
Available on cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn swap(&self, other: impl CastInto<Ref<QJsonValue>>)
cpp_lib_version="5.11.3"
or cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Swaps the value other with this. This operation is very fast and never fails.
Calls C++ function: void QJsonValue::swap(QJsonValue& other)
.
Swaps the value other with this. This operation is very fast and never fails.
This function was introduced in Qt 5.10.
sourcepub unsafe fn to_array_0a(&self) -> CppBox<QJsonArray>
pub unsafe fn to_array_0a(&self) -> CppBox<QJsonArray>
This is an overloaded function.
Calls C++ function: QJsonArray QJsonValue::toArray() const
.
This is an overloaded function.
Converts the value to an array and returns it.
If type() is not Array, a QJsonArray() will be returned.
sourcepub unsafe fn to_array_1a(
&self,
default_value: impl CastInto<Ref<QJsonArray>>
) -> CppBox<QJsonArray>
pub unsafe fn to_array_1a( &self, default_value: impl CastInto<Ref<QJsonArray>> ) -> CppBox<QJsonArray>
Converts the value to an array and returns it.
Calls C++ function: QJsonArray QJsonValue::toArray(const QJsonArray& defaultValue) const
.
Converts the value to an array and returns it.
If type() is not Array, the defaultValue will be returned.
sourcepub unsafe fn to_bool_1a(&self, default_value: bool) -> bool
pub unsafe fn to_bool_1a(&self, default_value: bool) -> bool
Converts the value to a bool and returns it.
Calls C++ function: bool QJsonValue::toBool(bool defaultValue = …) const
.
Converts the value to a bool and returns it.
If type() is not bool, the defaultValue will be returned.
sourcepub unsafe fn to_bool_0a(&self) -> bool
pub unsafe fn to_bool_0a(&self) -> bool
Converts the value to a bool and returns it.
Calls C++ function: bool QJsonValue::toBool() const
.
Converts the value to a bool and returns it.
If type() is not bool, the defaultValue will be returned.
sourcepub unsafe fn to_double_1a(&self, default_value: c_double) -> c_double
pub unsafe fn to_double_1a(&self, default_value: c_double) -> c_double
Converts the value to a double and returns it.
Calls C++ function: double QJsonValue::toDouble(double defaultValue = …) const
.
Converts the value to a double and returns it.
If type() is not Double, the defaultValue will be returned.
sourcepub unsafe fn to_double_0a(&self) -> c_double
pub unsafe fn to_double_0a(&self) -> c_double
Converts the value to a double and returns it.
Calls C++ function: double QJsonValue::toDouble() const
.
Converts the value to a double and returns it.
If type() is not Double, the defaultValue will be returned.
sourcepub unsafe fn to_int_1a(&self, default_value: c_int) -> c_int
pub unsafe fn to_int_1a(&self, default_value: c_int) -> c_int
Converts the value to an int and returns it.
Calls C++ function: int QJsonValue::toInt(int defaultValue = …) const
.
Converts the value to an int and returns it.
If type() is not Double or the value is not a whole number, the defaultValue will be returned.
sourcepub unsafe fn to_int_0a(&self) -> c_int
pub unsafe fn to_int_0a(&self) -> c_int
Converts the value to an int and returns it.
Calls C++ function: int QJsonValue::toInt() const
.
Converts the value to an int and returns it.
If type() is not Double or the value is not a whole number, the defaultValue will be returned.
sourcepub unsafe fn to_object_0a(&self) -> CppBox<QJsonObject>
pub unsafe fn to_object_0a(&self) -> CppBox<QJsonObject>
This is an overloaded function.
Calls C++ function: QJsonObject QJsonValue::toObject() const
.
This is an overloaded function.
Converts the value to an object and returns it.
If type() is not Object, the QJsonObject() will be returned.
sourcepub unsafe fn to_object_1a(
&self,
default_value: impl CastInto<Ref<QJsonObject>>
) -> CppBox<QJsonObject>
pub unsafe fn to_object_1a( &self, default_value: impl CastInto<Ref<QJsonObject>> ) -> CppBox<QJsonObject>
Converts the value to an object and returns it.
Calls C++ function: QJsonObject QJsonValue::toObject(const QJsonObject& defaultValue) const
.
Converts the value to an object and returns it.
If type() is not Object, the defaultValue will be returned.
sourcepub unsafe fn to_string_0a(&self) -> CppBox<QString>
pub unsafe fn to_string_0a(&self) -> CppBox<QString>
Converts the value to a QString and returns it.
Calls C++ function: QString QJsonValue::toString() const
.
Converts the value to a QString and returns it.
If type() is not String, a null QString will be returned.
See also QString::isNull().
sourcepub unsafe fn to_string_1a(
&self,
default_value: impl CastInto<Ref<QString>>
) -> CppBox<QString>
pub unsafe fn to_string_1a( &self, default_value: impl CastInto<Ref<QString>> ) -> CppBox<QString>
Converts the value to a QString and returns it.
Calls C++ function: QString QJsonValue::toString(const QString& defaultValue) const
.
sourcepub unsafe fn to_variant(&self) -> CppBox<QVariant>
pub unsafe fn to_variant(&self) -> CppBox<QVariant>
Converts the value to a QVariant().
Calls C++ function: QVariant QJsonValue::toVariant() const
.
Converts the value to a QVariant().
The QJsonValue types will be converted as follows:
See also fromVariant().
sourcepub unsafe fn type_(&self) -> Type
pub unsafe fn type_(&self) -> Type
Returns the type of the value.
Calls C++ function: QJsonValue::Type QJsonValue::type() const
.
Returns the type of the value.
See also QJsonValue::Type.