Qt中的JSON类与c++中的其他JSON解析器

JSON classes in Qt vs other JSON parsers in C++

本文关键字:JSON 其他 中的 类与 c++ Qt      更新时间:2023-10-16

我正在用c++开发一个服务器/客户端应用程序,我使用Qt作为我的IDE以及它的一些库。在性能方面,我被告知在服务器和客户端之间传输数据的最佳方式之一是通过JSON。然而,我想知道在Qt (QJsonArray,QJsonObject..)中解析JSON的默认类之间的性能差异。等)和其他c++解析器,例如JSON++ .

如果Qt类性能不够,您可以查看RapidJson: https://github.com/miloyip/rapidjson

性能比较:http://code.google.com/p/rapidjson/wiki/Performance

RapidJson的优点(除了它的速度)是容易安装和使用。来自他们的网站:

rapidjson是一个头文件库。这意味着,唯一要做的就是复制rapidjson/include/rapidjson及其子目录到你的项目或其他包含路径。

这个例子也来自他们的维基页面:

#include "rapidjson/document.h"
#include <cstdio>
int main() {
    const char json[] = "{ "hello" : "world" }";
    rapidjson::Document d;
    d.Parse<0>(json);
    printf("%sn", d["hello"].GetString());
    return 0;
}