步骤1:应该导入的头文件
#include <QJsonObject>
#include <QJsonDocument>
#include <QByteArray>
#include <QFile>
#include <QJsonArray>
#include<QJsonDocument>
#include <QDebug>
步骤2:创建json对象,并且将其转化为json字符串,又在将字符串解析出来
void MainWindow::cjygjsonzfc()//创建一个json字符串
{
QJsonArray jsonsz;//定义一个json数组
QJsonObject json;//定义一个json对象
json.insert("Name", "憨憨");//给json对象赋值
json.insert("From", 2016);//给json对象赋值
json.insert("Cross Platform", true);//给json对象赋值
jsonsz.append(json);//将json对象存入json数组中
QString hh;
QString dx;
QJsonDocument cs(jsonsz);
QJsonDocument sc(json);
hh=cs.toJson();
dx=sc.toJson();
this->jsdxzfc=dx;
this->json=hh;
ui->textEdit->setText(hh);
ui->textEdit->show();
}
void MainWindow::jiexijsonzfc()//解析json字符串
{
QString json=this->