Obsolete Members for QBinaryJson

QBinaryJson 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够继续运行。我们强烈建议不要在新代码中使用它们。

函数

(deprecated in 6.12) const char *toRawData(const QJsonDocument &document, int *size)

函数文档

[deprecated in 6.12] const char *QBinaryJson::toRawData(const QJsonDocument &document, int *size)

自 6.12 版本起,该函数已被废弃。我们强烈建议不要在新代码中使用它。

请改用 `toBinaryData()`。

返回 `document` 的原始二进制表示形式。`size ` 将包含返回数据的大小。

此方法可用于将 JSON 文档以二进制形式流式传输到文件等场景。

警告:在 Qt 6中 ,与 Qt 5 不同,调用者将拥有返回数据的所有权,并在不再需要时必须使用 `free() ` 将其释放。请使用 `toBinaryData()` 将二进制表示形式获取到 `QByteArray` 中,该对象会自动管理内存。

注意: 二进制 JSON 编码仅出于向后兼容性而保留。该功能未在文档中说明,且对可编码 JSON 文档的最大大小存在限制。 Qt JSON 类型可转换为 Qt CBOR 类型,后者又可序列化为 CBOR 二进制格式,反之亦然。CBOR 格式是一种定义明确且限制较少的二进制表示形式,适用于 JSON 的超集。

另请参阅 fromRawData()、fromBinaryData()、toBinaryData() 以及QCborValue 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.