包含的函数用于转换 QJsonDocument 到/从 JSON 二进制格式。 更多...
头: | #include <QBinaryJson> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(mytarget PRIVATE Qt6::Core5Compat) |
qmake: | QT += core5compat |
enum | DataValidation { Validate, BypassValidation } |
QJsonDocument | fromBinaryData (const QByteArray & data , QBinaryJson::DataValidation validation = Validate) |
QJsonDocument | fromRawData (const char * data , int size , QBinaryJson::DataValidation validation = Validate) |
QByteArray | toBinaryData (const QJsonDocument & document ) |
const char * | toRawData (const QJsonDocument & document , int * size ) |
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.
此枚举用于告诉 QJsonDocument whether to validate the binary data when converting to a QJsonDocument 使用 fromBinaryData () 或 fromRawData ().
常量 | 值 | 描述 |
---|---|---|
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. |
创建 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.
注意: 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.
另请参阅 toBinaryData (), fromRawData (), DataValidation ,和 QCborValue .
创建 QJsonDocument that uses the first size 字节来自 data . It assumes data contains a binary encoded JSON document. The created document does not take ownership of data . The data is copied into a different data structure, and the original data can be deleted or modified afterwards.
data 必须对齐 4 字节边界。
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.
返回 QJsonDocument 表示数据。
注意: 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.
注意: Before Qt 5.15, the caller had to guarantee that data would not be deleted or modified as long as any QJsonDocument , QJsonObject or QJsonArray still referenced the data. From Qt 5.15 on, this is not necessary anymore.
另请参阅 toRawData (), fromBinaryData (), DataValidation ,和 QCborValue .
返回二进制表示为 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.
注意: 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.
另请参阅 fromBinaryData () 和 QCborValue .
返回原生二进制表示为 document . size 将包含返回数据的大小。
This method is useful to e.g. stream the JSON document in its binary form to a file.
注意: 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.
另请参阅 fromRawData (), fromBinaryData (), toBinaryData (),和 QCborValue .