一. QString或者string 转为JSON格式
1. 导入头文件
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
2. 代码示例
QString str = "{\"111\":\"222\" , \"333\":\"444\"}" ; //如需转为标准string str.toStdString()
//string类型 需要导入<iostream>
//std::string str = "{\"111\":\"222\" , \"333\":\"444\"}" ;
//QJsonParseError 类用于在 JSON 解析中报告错误
QJsonParseError JSON_Error;
/*QJsonDocument 类用于读和写 JSON 文档从基于文本的表示转化为 QJsonDocument
* fromJson 文本 转为JSON
* toJson() 则可以反向转化为文本。
* 解析器非常快且高效,并将 JSON 转换为 Qt 使用的二进制表示。
* 已解析文档的有效性,可以使用 !isNull() 进行查询*/
QJsonDocument doc = QJsonDocument::fromJson(str.toStdString().c_str(),