QBinaryJson Namespace
Contains functions for converting QJsonDocument to and from JSON binary format. More...
Header: | #include <QBinaryJson> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core5Compat) target_link_libraries(mytarget PRIVATE Qt6::Core5Compat) |
qmake: | QT += core5compat |
Types
enum | DataValidation { Validate, BypassValidation } |
Functions
const int * | toRawData(const int &document, int *size) |
Detailed Description
This namespace provides utility functions to keep compatibility with older code, which uses the JSON binary format for serializing JSON. Qt JSON types can be converted to Qt CBOR types, which can in turn be serialized into the CBOR binary format and vice versa.
Type Documentation
enum QBinaryJson::DataValidation
This enum is used to tell QJsonDocument whether to validate the binary data when converting to a QJsonDocument using fromBinaryData() or fromRawData().
Constant | Value | Description |
---|---|---|
QBinaryJson::Validate | 0 | Validate the data before using it. This is the default. |
QBinaryJson::BypassValidation | 1 | Bypasses data validation. Only use if you received the data from a trusted place and know it's valid, as using of invalid data can crash the application. |
Function Documentation
const int *QBinaryJson::toRawData(const int &document, int *size)
Returns the raw binary representation of document. size will contain the size of the returned data.
This method is useful to e.g. stream the JSON document in its binary form to a file.
Note: The binary JSON encoding is only retained for backwards compatibility. It is undocumented and restrictive in the maximum size of JSON documents that can be encoded. Qt JSON types can be converted to Qt CBOR types, which can in turn be serialized into the CBOR binary format and vice versa. The CBOR format is a well-defined and less restrictive binary representation for a superset of JSON.
See also fromRawData(), fromBinaryData(), toBinaryData(), and QCborValue.