[][src]Struct qt_core::QJsonDocument

#[repr(C)]pub struct QJsonDocument { /* fields omitted */ }

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

Methods

impl QJsonDocument[src]

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

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

pub unsafe fn binary_format_tag() -> c_uint[src]

Returns the value of the BinaryFormatTag field.

pub unsafe fn copy_from(
    &self,
    other: impl CastInto<Ref<QJsonDocument>>
) -> Ref<QJsonDocument>
[src]

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.

pub unsafe fn from_binary_data_2a(
    data: impl CastInto<Ref<QByteArray>>,
    validation: DataValidation
) -> CppBox<QJsonDocument>
[src]

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.

pub unsafe fn from_binary_data_1a(
    data: impl CastInto<Ref<QByteArray>>
) -> CppBox<QJsonDocument>
[src]

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.

pub unsafe fn from_json_2a(
    json: impl CastInto<Ref<QByteArray>>,
    error: impl CastInto<Ptr<QJsonParseError>>
) -> CppBox<QJsonDocument>
[src]

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

pub unsafe fn from_json_1a(
    json: impl CastInto<Ref<QByteArray>>
) -> CppBox<QJsonDocument>
[src]

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

pub unsafe fn from_raw_data_3a(
    data: *const c_char,
    size: c_int,
    validation: DataValidation
) -> CppBox<QJsonDocument>
[src]

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.

pub unsafe fn from_raw_data_2a(
    data: *const c_char,
    size: c_int
) -> CppBox<QJsonDocument>
[src]

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.

pub unsafe fn from_variant(
    variant: impl CastInto<Ref<QVariant>>
) -> CppBox<QJsonDocument>
[src]

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

pub unsafe fn index_q_string(
    &self,
    key: impl CastInto<Ref<QString>>
) -> CppBox<QJsonValue>
[src]

This is supported 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.

pub unsafe fn index_q_latin1_string(
    &self,
    key: impl CastInto<Ref<QLatin1String>>
) -> CppBox<QJsonValue>
[src]

This is supported 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.

pub unsafe fn index_int(&self, i: c_int) -> CppBox<QJsonValue>[src]

This is supported 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.

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

This is supported 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.

pub unsafe fn is_array(&self) -> bool[src]

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

pub unsafe fn is_empty(&self) -> bool[src]

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.

pub unsafe fn is_null(&self) -> bool[src]

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.

pub unsafe fn is_object(&self) -> bool[src]

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

pub unsafe fn new() -> CppBox<QJsonDocument>[src]

Constructs an empty and invalid document.

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

C++ documentation:

Constructs an empty and invalid document.

pub unsafe fn from_q_json_object(
    object: impl CastInto<Ref<QJsonObject>>
) -> CppBox<QJsonDocument>
[src]

Creates a QJsonDocument from object.

Calls C++ function: [constructor] void QJsonDocument::QJsonDocument(const QJsonObject& object).

C++ documentation:

Creates a QJsonDocument from object.

pub unsafe fn from_q_json_array(
    array: impl CastInto<Ref<QJsonArray>>
) -> CppBox<QJsonDocument>
[src]

Constructs a QJsonDocument from array.

Calls C++ function: [constructor] void QJsonDocument::QJsonDocument(const QJsonArray& array).

C++ documentation:

Constructs a QJsonDocument from array.

pub unsafe fn new_copy(
    other: impl CastInto<Ref<QJsonDocument>>
) -> CppBox<QJsonDocument>
[src]

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.

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

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

pub unsafe fn raw_data(&self, size: *mut c_int) -> *const c_char[src]

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.

pub unsafe fn set_array(&self, array: impl CastInto<Ref<QJsonArray>>)[src]

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

pub unsafe fn set_object(&self, object: impl CastInto<Ref<QJsonObject>>)[src]

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

pub unsafe fn swap(&self, other: impl CastInto<Ref<QJsonDocument>>)[src]

This is supported 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.

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

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

pub unsafe fn to_json_0a(&self) -> CppBox<QByteArray>[src]

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.

pub unsafe fn to_json_1a(&self, format: JsonFormat) -> CppBox<QByteArray>[src]

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.

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

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

impl CppDeletable for QJsonDocument[src]

unsafe fn delete(&self)[src]

Deletes the document.

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

C++ documentation:

Deletes the document.

Binary data set with fromRawData is not freed.

impl PartialEq<Ref<QJsonDocument>> for QJsonDocument[src]

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

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.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.