c++ - 如何在 Qt 中使用 QJson 库

标签 c++ qt qt5 qtcore qjson

现在我使用Qt v2.3 我有一个问题,我需要使用 json 将数据发送到服务器,但 Qjson 类不存在。 如何将 JSON 包含到 Qt 中?或者 是否有任何外部头文件?

最佳答案

您可能指的是 QtCreator 版本而不是 Qt。 Qt 2.3 作为所使用的框架版本已经非常老了,而且无论如何,大多数第三方库可能都不再使用它了。

只需使用 Qt 5,这意味着如果您还没有这样做,就切换到它。

然后您将可以访问qt json classes in QtCore突然间。基本上,您将可以访问这些类:

QJsonArray Encapsulates a JSON array

QJsonDocument Way to read and write JSON documents

QJsonObject Encapsulates a JSON object

QJsonObject::iterator QJsonObject::iterator class provides an STL-style non-const iterator for QJsonObject

QJsonObject::const_iterator QJsonObject::const_iterator class provides an STL-style const iterator for QJsonObject

QJsonParseError Used to report errors during JSON parsing

QJsonValue Encapsulates a value in JSON

在这里您可以或多或少地找到有关这些类的使用的一个很好的示例:

JSON Save Game Example

如果您有 Qt 4 系列或更早版本,您可以尝试向后移植这些类(如果没有人这样做的话)。

这些类的总体优势在于,与其他库相比,它们速度极快,例如 qjson(4-5 倍),甚至是用 C 编写的 libjson 库!这是可能的,因为它内部使用二进制格式来加速读写操作。

关于c++ - 如何在 Qt 中使用 QJson 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22959848/

相关文章:

c++ - 带模糊角的透明窗口

c++ - 如何获取 LIST 命令的响应消息(来自 CFTPConnection)

c++ - C++中头文件的 namespace

c++ - 成员函数指针

multithreading - 为什么没有 Qt 连接模式在 Qt::DirectConnection 和 Qt::BlockingQueuedConnection 之间自动选择?

c++ - 为什么使用 QQuickWindow::grabWindow() 会导致窗口变成图像?

c++ - 如何在 Qt 中为文本编辑程序实现 "Do you want to save changes?"对话框?

c++ - Qt deleteLater 跨线程

c++ - Qt5:如何使用 State 正确设置 ProgressBar

qt - 为什么我的 QT 应用程序不起作用?