Struct qt_core::QJsonDocument
source · #[repr(C)]pub struct QJsonDocument { /* private fields */ }
Expand description
The QJsonDocument class provides a way to read and write JSON documents.
C++ class: QJsonDocument
.
The QJsonDocument class provides a way to read and write JSON documents.
QJsonDocument is a class that wraps a complete JSON document and can read and write this document both from a UTF-8 encoded text based representation as well as Qt's own binary format.
A JSON document can be converted from its text-based representation to a QJsonDocument using QJsonDocument::fromJson(). toJson() converts it back to text. The parser is very fast and efficient and converts the JSON to the binary representation used by Qt.
Validity of the parsed document can be queried with !isNull()
A document can be queried as to whether it contains an array or an object using isArray() and isObject(). The array or object contained in the document can be retrieved using array() or object() and then read or manipulated.
A document can also be created from a stored binary representation using fromBinaryData() or fromRawData().
Implementations§
source§impl QJsonDocument
impl QJsonDocument
sourcepub unsafe fn array(&self) -> CppBox<QJsonArray>
pub unsafe fn array(&self) -> CppBox<QJsonArray>
Returns the QJsonArray contained in the document.
Calls C++ function: QJsonArray QJsonDocument::array() const
.
Returns the QJsonArray contained in the document.
Returns an empty array if the document contains an object.
sourcepub unsafe fn binary_format_tag() -> c_uint
pub unsafe fn binary_format_tag() -> c_uint
Returns the value of the BinaryFormatTag
field.
sourcepub unsafe fn copy_from(
&self,
other: impl CastInto<Ref<QJsonDocument>>
) -> Ref<QJsonDocument>
pub unsafe fn copy_from( &self, other: impl CastInto<Ref<QJsonDocument>> ) -> Ref<QJsonDocument>
Assigns the other document to this QJsonDocument. Returns a reference to this object.
Calls C++ function: QJsonDocument& QJsonDocument::operator=(const QJsonDocument& other)
.
Assigns the other document to this QJsonDocument. Returns a reference to this object.
sourcepub unsafe fn from_binary_data_2a(
data: impl CastInto<Ref<QByteArray>>,
validation: DataValidation
) -> CppBox<QJsonDocument>
pub unsafe fn from_binary_data_2a( data: impl CastInto<Ref<QByteArray>>, validation: DataValidation ) -> CppBox<QJsonDocument>
Creates a QJsonDocument from data.
Calls C++ function: static QJsonDocument QJsonDocument::fromBinaryData(const QByteArray& data, QJsonDocument::DataValidation validation = …)
.
Creates a QJsonDocument from data.
validation decides whether the data is checked for validity before being used. By default the data is validated. If the data is not valid, the method returns a null document.
See also toBinaryData(), fromRawData(), isNull(), and DataValidation.
sourcepub unsafe fn from_binary_data_1a(
data: impl CastInto<Ref<QByteArray>>
) -> CppBox<QJsonDocument>
pub unsafe fn from_binary_data_1a( data: impl CastInto<Ref<QByteArray>> ) -> CppBox<QJsonDocument>
Creates a QJsonDocument from data.
Calls C++ function: static QJsonDocument QJsonDocument::fromBinaryData(const QByteArray& data)
.
Creates a QJsonDocument from data.
validation decides whether the data is checked for validity before being used. By default the data is validated. If the data is not valid, the method returns a null document.
See also toBinaryData(), fromRawData(), isNull(), and DataValidation.
sourcepub unsafe fn from_json_2a(
json: impl CastInto<Ref<QByteArray>>,
error: impl CastInto<Ptr<QJsonParseError>>
) -> CppBox<QJsonDocument>
pub unsafe fn from_json_2a( json: impl CastInto<Ref<QByteArray>>, error: impl CastInto<Ptr<QJsonParseError>> ) -> CppBox<QJsonDocument>
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
Calls C++ function: static QJsonDocument QJsonDocument::fromJson(const QByteArray& json, QJsonParseError* error = …)
.
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
Returns a valid (non-null) QJsonDocument if the parsing succeeds. If it fails, the returned document will be null, and the optional error variable will contain further details about the error.
See also toJson(), QJsonParseError, and isNull().
sourcepub unsafe fn from_json_1a(
json: impl CastInto<Ref<QByteArray>>
) -> CppBox<QJsonDocument>
pub unsafe fn from_json_1a( json: impl CastInto<Ref<QByteArray>> ) -> CppBox<QJsonDocument>
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
Calls C++ function: static QJsonDocument QJsonDocument::fromJson(const QByteArray& json)
.
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
Returns a valid (non-null) QJsonDocument if the parsing succeeds. If it fails, the returned document will be null, and the optional error variable will contain further details about the error.
See also toJson(), QJsonParseError, and isNull().
sourcepub unsafe fn from_raw_data_3a(
data: *const c_char,
size: c_int,
validation: DataValidation
) -> CppBox<QJsonDocument>
pub unsafe fn from_raw_data_3a( data: *const c_char, size: c_int, validation: DataValidation ) -> CppBox<QJsonDocument>
Creates a QJsonDocument that uses the first size bytes from data. It assumes data contains a binary encoded JSON document. The created document does not take ownership of data and the caller has to guarantee that data will not be deleted or modified as long as any QJsonDocument, QJsonObject or QJsonArray still references the data.
Calls C++ function: static QJsonDocument QJsonDocument::fromRawData(const char* data, int size, QJsonDocument::DataValidation validation = …)
.
Creates a QJsonDocument that uses the first size bytes from data. It assumes data contains a binary encoded JSON document. The created document does not take ownership of data and the caller has to guarantee that data will not be deleted or modified as long as any QJsonDocument, QJsonObject or QJsonArray still references the data.
data has to be aligned to a 4 byte boundary.
validation decides whether the data is checked for validity before being used. By default the data is validated. If the data is not valid, the method returns a null document.
Returns a QJsonDocument representing the data.
See also rawData(), fromBinaryData(), isNull(), and DataValidation.
sourcepub unsafe fn from_raw_data_2a(
data: *const c_char,
size: c_int
) -> CppBox<QJsonDocument>
pub unsafe fn from_raw_data_2a( data: *const c_char, size: c_int ) -> CppBox<QJsonDocument>
Creates a QJsonDocument that uses the first size bytes from data. It assumes data contains a binary encoded JSON document. The created document does not take ownership of data and the caller has to guarantee that data will not be deleted or modified as long as any QJsonDocument, QJsonObject or QJsonArray still references the data.
Calls C++ function: static QJsonDocument QJsonDocument::fromRawData(const char* data, int size)
.
Creates a QJsonDocument that uses the first size bytes from data. It assumes data contains a binary encoded JSON document. The created document does not take ownership of data and the caller has to guarantee that data will not be deleted or modified as long as any QJsonDocument, QJsonObject or QJsonArray still references the data.
data has to be aligned to a 4 byte boundary.
validation decides whether the data is checked for validity before being used. By default the data is validated. If the data is not valid, the method returns a null document.
Returns a QJsonDocument representing the data.
See also rawData(), fromBinaryData(), isNull(), and DataValidation.
sourcepub unsafe fn from_variant(
variant: impl CastInto<Ref<QVariant>>
) -> CppBox<QJsonDocument>
pub unsafe fn from_variant( variant: impl CastInto<Ref<QVariant>> ) -> CppBox<QJsonDocument>
Creates a QJsonDocument from the QVariant variant.
Calls C++ function: static QJsonDocument QJsonDocument::fromVariant(const QVariant& variant)
.
Creates a QJsonDocument from the QVariant variant.
If the variant contains any other type than a QVariantMap, QVariantHash, QVariantList or QStringList, the returned document is invalid.
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 QJsonDocument::operator[](const QString& key) const
.
Returns a QJsonValue representing the value for the key key.
Equivalent to calling object().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 QJsonDocument::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 QJsonDocument::operator[](int i) const
.
Returns a QJsonValue representing the value for index i.
Equivalent to calling array().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 QJsonDocument::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 document contains an array.
Calls C++ function: bool QJsonDocument::isArray() const
.
sourcepub unsafe fn is_empty(&self) -> bool
pub unsafe fn is_empty(&self) -> bool
Returns true
if the document doesn't contain any data.
Calls C++ function: bool QJsonDocument::isEmpty() const
.
Returns true
if the document doesn’t contain any data.
sourcepub unsafe fn is_null(&self) -> bool
pub unsafe fn is_null(&self) -> bool
returns true
if this document is null.
Calls C++ function: bool QJsonDocument::isNull() const
.
returns true
if this document is null.
Null documents are documents created through the default constructor.
Documents created from UTF-8 encoded text or the binary format are validated during parsing. If validation fails, the returned document will also be null.
sourcepub unsafe fn is_object(&self) -> bool
pub unsafe fn is_object(&self) -> bool
Returns true
if the document contains an object.
Calls C++ function: bool QJsonDocument::isObject() const
.
sourcepub unsafe fn new() -> CppBox<QJsonDocument>
pub unsafe fn new() -> CppBox<QJsonDocument>
Constructs an empty and invalid document.
Calls C++ function: [constructor] void QJsonDocument::QJsonDocument()
.
Constructs an empty and invalid document.
sourcepub unsafe fn from_q_json_object(
object: impl CastInto<Ref<QJsonObject>>
) -> CppBox<QJsonDocument>
pub unsafe fn from_q_json_object( object: impl CastInto<Ref<QJsonObject>> ) -> CppBox<QJsonDocument>
Creates a QJsonDocument from object.
Calls C++ function: [constructor] void QJsonDocument::QJsonDocument(const QJsonObject& object)
.
Creates a QJsonDocument from object.
sourcepub unsafe fn from_q_json_array(
array: impl CastInto<Ref<QJsonArray>>
) -> CppBox<QJsonDocument>
pub unsafe fn from_q_json_array( array: impl CastInto<Ref<QJsonArray>> ) -> CppBox<QJsonDocument>
Constructs a QJsonDocument from array.
Calls C++ function: [constructor] void QJsonDocument::QJsonDocument(const QJsonArray& array)
.
Constructs a QJsonDocument from array.
sourcepub unsafe fn new_copy(
other: impl CastInto<Ref<QJsonDocument>>
) -> CppBox<QJsonDocument>
pub unsafe fn new_copy( other: impl CastInto<Ref<QJsonDocument>> ) -> CppBox<QJsonDocument>
Creates a copy of the other document.
Calls C++ function: [constructor] void QJsonDocument::QJsonDocument(const QJsonDocument& other)
.
Creates a copy of the other document.
sourcepub unsafe fn object(&self) -> CppBox<QJsonObject>
pub unsafe fn object(&self) -> CppBox<QJsonObject>
Returns the QJsonObject contained in the document.
Calls C++ function: QJsonObject QJsonDocument::object() const
.
Returns the QJsonObject contained in the document.
Returns an empty object if the document contains an array.
sourcepub unsafe fn raw_data(&self, size: *mut c_int) -> *const c_char
pub unsafe fn raw_data(&self, size: *mut c_int) -> *const c_char
Returns the raw binary representation of the data size will contain the size of the returned data.
Calls C++ function: const char* QJsonDocument::rawData(int* size) const
.
Returns the raw binary representation of the data size will contain the size of the returned data.
This method is useful to e.g. stream the JSON document in it's binary form to a file.
sourcepub unsafe fn set_array(&self, array: impl CastInto<Ref<QJsonArray>>)
pub unsafe fn set_array(&self, array: impl CastInto<Ref<QJsonArray>>)
Sets array as the main object of this document.
Calls C++ function: void QJsonDocument::setArray(const QJsonArray& array)
.
sourcepub unsafe fn set_object(&self, object: impl CastInto<Ref<QJsonObject>>)
pub unsafe fn set_object(&self, object: impl CastInto<Ref<QJsonObject>>)
Sets object as the main object of this document.
Calls C++ function: void QJsonDocument::setObject(const QJsonObject& object)
.
sourcepub unsafe fn swap(&self, other: impl CastInto<Ref<QJsonDocument>>)
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<QJsonDocument>>)
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 document other with this. This operation is very fast and never fails.
Calls C++ function: void QJsonDocument::swap(QJsonDocument& other)
.
Swaps the document other with this. This operation is very fast and never fails.
This function was introduced in Qt 5.10.
sourcepub unsafe fn to_binary_data(&self) -> CppBox<QByteArray>
pub unsafe fn to_binary_data(&self) -> CppBox<QByteArray>
Returns a binary representation of the document.
Calls C++ function: QByteArray QJsonDocument::toBinaryData() const
.
Returns a binary representation of the document.
The binary representation is also the native format used internally in Qt, and is very efficient and fast to convert to and from.
The binary format can be stored on disk and interchanged with other applications or computers. fromBinaryData() can be used to convert it back into a JSON document.
See also fromBinaryData().
sourcepub unsafe fn to_json_0a(&self) -> CppBox<QByteArray>
pub unsafe fn to_json_0a(&self) -> CppBox<QByteArray>
Converts the QJsonDocument to a UTF-8 encoded JSON document in the provided format.
Calls C++ function: QByteArray QJsonDocument::toJson() const
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for QByteArray QJsonDocument::toJson(JsonFormat format = Indented) const
:
Converts the QJsonDocument to a UTF-8 encoded JSON document in the provided format.
See also fromJson() and JsonFormat.
sourcepub unsafe fn to_json_1a(&self, format: JsonFormat) -> CppBox<QByteArray>
pub unsafe fn to_json_1a(&self, format: JsonFormat) -> CppBox<QByteArray>
Converts the QJsonDocument to a UTF-8 encoded JSON document in the provided format.
Calls C++ function: QByteArray QJsonDocument::toJson(QJsonDocument::JsonFormat format) const
.
Converts the QJsonDocument to a UTF-8 encoded JSON document in the provided format.
See also fromJson() and JsonFormat.
sourcepub unsafe fn to_variant(&self) -> CppBox<QVariant>
pub unsafe fn to_variant(&self) -> CppBox<QVariant>
Returns a QVariant representing the Json document.
Calls C++ function: QVariant QJsonDocument::toVariant() const
.
Returns a QVariant representing the Json document.
The returned variant will be a QVariantList if the document is a QJsonArray and a QVariantMap if the document is a QJsonObject.
See also fromVariant() and QJsonValue::toVariant().
Trait Implementations§
source§impl CppDeletable for QJsonDocument
impl CppDeletable for QJsonDocument
source§unsafe fn delete(&self)
unsafe fn delete(&self)
Deletes the document.
Calls C++ function: [destructor] void QJsonDocument::~QJsonDocument()
.
Deletes the document.
Binary data set with fromRawData is not freed.