RapidJson与QtJson解析器互操作示例
1、JSON内容
{
"ClassName": "高三",
"Grade": "3",
"Student": [
{
"Name": "张三",
"ID": "001",
"Province": "内蒙古"
},
{
"Name": "李四",
"ID": "002",
"Province": "浙江"
},
{
"Name": "王五",
"ID": "003",
"Province": "江苏"
}
],
"Subject": [
"Mathematic",
"Physics",
"Biology",
"Chemical",
"Gymnastic"
]
}
2、解析代码
#include <QCoreApplication>
#include <QDebug>
#include <string>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/prettywriter.h"
std::string MakeQtJson()
{
QJsonArray subject;
subject.append("Mathematic");
subject.append("Physics");
subject.append("Biology");
subject.append("Chemical");
subject.append("Gymnastic");
QJsonObject zs;
zs.insert("ID","001");
zs.insert("Name",QStringLiteral("张三"));
zs.insert("Province",QStringLiteral("内蒙古"));
QJsonObject ls;
ls.insert("ID","002");
ls.insert("Name",QStringLiteral("李四"));
ls.insert("Province",QStringLiteral("浙江"));
QJsonObject ww;
ww.insert("ID","003");
ww.insert("Name",QStringLiteral("王五"));
ww.insert("Province",QStringLiteral("江苏"));
QJsonArray student;
student.append(QJsonValue(zx))