读写json文件

这篇博客详细介绍了如何在C++中进行JSON文件的读取和写入操作,包括所需的头文件和关键代码示例。
摘要由CSDN通过智能技术生成

头文件


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariantMap>
#include <QFile>
#include <QDebug>
#include <QMessageBox>

//通道信息
typedef struct _STChannelInfo
{
   
    QString uuid;    //标识
    QString strName; //名称
    QList<QStringList> paraValue;//参数值
    void operator=(const _STChannelInfo &other )
    {
   
        this->uuid = other.uuid;
        this->strName = other.strName;
        this->paraValue = other.paraValue;
    }
}STChannelInfo;

//板卡信息
typedef struct _STCardInfo
{
   
    QString uuid;    //标识
    QString strName; //名称
    QList<STChannelInfo> channelInfo;

    void operator=(const _STCardInfo &other )
    {
   
        this->uuid = other.uuid;
        this->strName = other.strName;
        this->channelInfo = other.channelInfo;
    }
}STCardInfo;

//设备信息
typedef struct _STDeviceInfo
{
   
    QString uuid;    //标识
    QString strName; //名称
    QList<STCardInfo> cardInfo;//板卡信息

    void operator=(const _STDeviceInfo &other )
    {
   
        this->uuid = other.uuid;
        this->strName = other.strName;
        this->cardInfo = other.cardInfo;
    }
}STDeviceInfo;

namespace Ui {
   
class MainWindow;
}

class MainWindow : public QMainWindow
{
   
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    QList<STDeviceInfo> m_deviceInfo;
private:
    Ui::MainWindow *ui;
    void iniVar();//初始化变量
    void writeJsonFile();//写json文件
    void readJsonFile();//读json文件
};

#endif // MAINWINDOW_H


CPP文件

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
   
    ui->setupUi(this);

    //--1 初始化变量
    iniVar();

    //--2 写json文件
    writeJsonFile();

    //--3 读json文件
    readJsonFile();
}

MainWindow::~MainWindow()
{
   
    delete ui;
}
// 初始化变量
void MainWindow::iniVar(
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值