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.

C++ documentation:

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

source

pub unsafe fn array(&self) -> CppBox<QJsonArray>

Returns the QJsonArray contained in the document.

Calls C++ function: QJsonArray QJsonDocument::array() const.

C++ documentation:

Returns the QJsonArray contained in the document.

Returns an empty array if the document contains an object.

See also isArray(), object(), and setArray().

source

pub unsafe fn binary_format_tag() -> c_uint

Returns the value of the BinaryFormatTag field.

source

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).

C++ documentation:

Assigns the other document to this QJsonDocument. Returns a reference to this object.

source

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 = …).

C++ documentation:

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.

source

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).

C++ documentation:

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.

source

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 = …).

C++ documentation:

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().

source

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).

C++ documentation:

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().

source

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 = …).

C++ documentation:

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.

source

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).

C++ documentation:

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.

source

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).

C++ documentation:

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().

source

pub 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.

Returns a QJsonValue representing the value for the key key.

Calls C++ function: QJsonValue QJsonDocument::operator[](const QString& key) const.

C++ documentation:

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.

source

pub 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.

This is an overloaded function.

Calls C++ function: QJsonValue QJsonDocument::operator[](QLatin1String key) const.

C++ documentation:

This is an overloaded function.

This function was introduced in Qt 5.10.

source

pub 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.

Returns a QJsonValue representing the value for index i.

Calls C++ function: QJsonValue QJsonDocument::operator[](int i) const.

C++ documentation:

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.

source

pub unsafe fn index_q_string_view( &self, key: impl CastInto<Ref<QStringView>> ) -> CppBox<QJsonValue>

Available on cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: QJsonValue QJsonDocument::operator[](QStringView key) const.

C++ documentation:

This is an overloaded function.

This function was introduced in Qt 5.14.

source

pub unsafe fn is_array(&self) -> bool

Returns true if the document contains an array.

Calls C++ function: bool QJsonDocument::isArray() const.

C++ documentation:

Returns true if the document contains an array.

See also array() and isObject().

source

pub unsafe fn is_empty(&self) -> bool

Returns true if the document doesn't contain any data.

Calls C++ function: bool QJsonDocument::isEmpty() const.

C++ documentation:

Returns true if the document doesn’t contain any data.

source

pub unsafe fn is_null(&self) -> bool

returns true if this document is null.

Calls C++ function: bool QJsonDocument::isNull() const.

C++ documentation:

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.

source

pub unsafe fn is_object(&self) -> bool

Returns true if the document contains an object.

Calls C++ function: bool QJsonDocument::isObject() const.

C++ documentation:

Returns true if the document contains an object.

See also object() and isArray().

source

pub unsafe fn new() -> CppBox<QJsonDocument>

Constructs an empty and invalid document.

Calls C++ function: [constructor] void QJsonDocument::QJsonDocument().

C++ documentation:

Constructs an empty and invalid document.

source

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).

C++ documentation:

Creates a QJsonDocument from object.

source

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).

C++ documentation:

Constructs a QJsonDocument from array.

source

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).

C++ documentation:

Creates a copy of the other document.

source

pub unsafe fn object(&self) -> CppBox<QJsonObject>

Returns the QJsonObject contained in the document.

Calls C++ function: QJsonObject QJsonDocument::object() const.

C++ documentation:

Returns the QJsonObject contained in the document.

Returns an empty object if the document contains an array.

See also isObject(), array(), and setObject().

source

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.

C++ documentation:

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.

source

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).

C++ documentation:

Sets array as the main object of this document.

See also setObject() and array().

source

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).

C++ documentation:

Sets object as the main object of this document.

See also setArray() and object().

source

pub 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.

Swaps the document other with this. This operation is very fast and never fails.

Calls C++ function: void QJsonDocument::swap(QJsonDocument& other).

C++ documentation:

Swaps the document other with this. This operation is very fast and never fails.

This function was introduced in Qt 5.10.

source

pub unsafe fn to_binary_data(&self) -> CppBox<QByteArray>

Returns a binary representation of the document.

Calls C++ function: QByteArray QJsonDocument::toBinaryData() const.

C++ documentation:

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().

source

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.

source

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.

C++ documentation:

Converts the QJsonDocument to a UTF-8 encoded JSON document in the provided format.

See also fromJson() and JsonFormat.

source

pub unsafe fn to_variant(&self) -> CppBox<QVariant>

Returns a QVariant representing the Json document.

Calls C++ function: QVariant QJsonDocument::toVariant() const.

C++ documentation:

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

source§

unsafe fn delete(&self)

Deletes the document.

Calls C++ function: [destructor] void QJsonDocument::~QJsonDocument().

C++ documentation:

Deletes the document.

Binary data set with fromRawData is not freed.

source§

impl PartialEq<Ref<QJsonDocument>> for QJsonDocument

source§

fn eq(&self, other: &Ref<QJsonDocument>) -> bool

Returns true if the other document is equal to this document.

Calls C++ function: bool QJsonDocument::operator==(const QJsonDocument& other) const.

C++ documentation:

Returns true if the other document is equal to this document.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.