?
(1)官网 BSON (Binary JSON) Serialization
(2)百度百科 BSON_百度百科
菜鸟教程 JSON 教程 | 菜鸟教程
#include <QCoreApplication>
#include <QJsonDocument>
#include <QFile>
#include <QDebug>
#include "bson/Value.h"
BSON::Value gbsonDoc = BSON::Object{{"undefined", BSON::Value{}},
{"int32", (BSON::int32)1},
{"int64", (BSON::int64)1},
{"double", 3.14},
{"true", true},
{"false", false},
{"string", "foobar"},
{"datetime", std::chrono::milliseconds{123}},
{"object", BSON::Object{{"foo", "bar"}}},
{"array", BSON::Array{1, 2, 3}}};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string bsonString = gbsonDoc.toBSON(); // bson结构->bson字符串
BSON::Value bsonDoc = BSON::Value::fromBSON(bsonString); // bson字符串->bson结构
QString jsonString = QString::fromLocal8Bit(gbsonDoc.toJSON().c_str()); // bson结构->json字符串
QJsonDocument jsonDoc = QJsonDocument::fromJson(QByteArray::fromStdString(bsonDoc.toJSON())); // bson结构->QJsonDocument
BSON::Value bsonDocfromJson = BSON::Value::fromJSON(std::string(const_cast<const char *>(jsonString.toLocal8Bit().constData()))); // json字符串->bson结构
qDebug() << "Bson String: " << QByteArray::fromStdString(bsonDoc.toJSON());
qDebug() << "Json String: " << jsonString;
qDebug() << "Json Document: " << jsonDoc;
return a.exec();
}
?参考:
https://github.com/trusch/libbson
资源:
QT 例子代码 - https://download.csdn.net/download/halo_hsuh/12284550