306 lines
11 KiB
C++
306 lines
11 KiB
C++
|
#include "readJsonFile.h"
|
||
|
|
||
|
QJsonArray readJson_testConfig()
|
||
|
{
|
||
|
/*QDir dir(JsonDir);
|
||
|
QString filePath = dir.absoluteFilePath("testConfig.json");*/
|
||
|
QJsonArray testJsonConfig;
|
||
|
//QFile file(filePath);
|
||
|
QFile file("./SourceCode/Json/JsonFile/testConfig.json");
|
||
|
//QFile file("funcConfig.json");
|
||
|
if (file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open testConfig.json";
|
||
|
QByteArray data = file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "File content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
testJsonConfig = doc.array();
|
||
|
qDebug() << "JSON array size:" << testJsonConfig.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse JSON document!";
|
||
|
}
|
||
|
file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open testConfig.json";
|
||
|
}
|
||
|
return testJsonConfig;
|
||
|
}
|
||
|
|
||
|
QJsonArray readJson_funcConfig()
|
||
|
{
|
||
|
QJsonArray funcJsonConfig;
|
||
|
QFile funcConfig_file("./SourceCode/Json/JsonFile/funcConfig.json");
|
||
|
if (funcConfig_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open funcConfig.json";
|
||
|
QByteArray data = funcConfig_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "funcConfig_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
funcJsonConfig = doc.array();
|
||
|
qDebug() << "funcJsonConfig JSON array size:" << funcJsonConfig.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "funcJsonConfig JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse funcJsonConfig JSON document!";
|
||
|
}
|
||
|
funcConfig_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open funcConfig.json";
|
||
|
}
|
||
|
return funcJsonConfig;
|
||
|
}
|
||
|
|
||
|
QJsonArray readJson_frontBoardOneClickTest()
|
||
|
{
|
||
|
QJsonArray frontBoardOneClickTest;
|
||
|
QFile frontBoardOneClickTest_file("./SourceCode/Json/JsonFile/frontBoardOneClickTest.json");
|
||
|
if (frontBoardOneClickTest_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open frontBoardOneClickTest.json";
|
||
|
QByteArray data = frontBoardOneClickTest_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "frontBoardOneClickTest_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
frontBoardOneClickTest = doc.array();
|
||
|
qDebug() << "frontBoardOneClickTest JSON array size:" << frontBoardOneClickTest.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "frontBoardOneClickTest JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse frontBoardOneClickTest JSON document!";
|
||
|
}
|
||
|
frontBoardOneClickTest_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open frontBoardOneClickTest.json";
|
||
|
}
|
||
|
return frontBoardOneClickTest;
|
||
|
}
|
||
|
|
||
|
QJsonArray readJson_frontBoardTest()
|
||
|
{
|
||
|
QJsonArray frontBoardTest;
|
||
|
QFile frontBoardTest_file("./SourceCode/Json/JsonFile/frontBoardTest.json");
|
||
|
if (frontBoardTest_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open frontBoardTest.json";
|
||
|
QByteArray data = frontBoardTest_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "frontBoardTest_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
frontBoardTest = doc.array();
|
||
|
qDebug() << "frontBoardTest JSON array size:" << frontBoardTest.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "frontBoardTest JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse frontBoardTest JSON document!";
|
||
|
}
|
||
|
frontBoardTest_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open frontBoardTest.json";
|
||
|
}
|
||
|
return frontBoardTest;
|
||
|
}
|
||
|
|
||
|
QJsonArray readJson_frontBoardFuncConfig()
|
||
|
{
|
||
|
QJsonArray frontBoardFuncConfig;
|
||
|
QFile frontBoardFuncConfig_file("./SourceCode/Json/JsonFile/frontBoardFuncConfig.json");
|
||
|
if (frontBoardFuncConfig_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open frontBoardFuncConfig.json";
|
||
|
QByteArray data = frontBoardFuncConfig_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "frontBoardFuncConfig_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
frontBoardFuncConfig = doc.array();
|
||
|
qDebug() << "frontBoardFuncConfig JSON array size:" << frontBoardFuncConfig.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "frontBoardFuncConfig JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse frontBoardFuncConfig JSON document!";
|
||
|
}
|
||
|
frontBoardFuncConfig_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open frontBoardFuncConfig.json";
|
||
|
}
|
||
|
return frontBoardFuncConfig;
|
||
|
}
|
||
|
|
||
|
//QJsonArray readJson_funcConfig()
|
||
|
//{
|
||
|
// QJsonArray funcJsonConfig;
|
||
|
// QFile funcConfig_file("./SourceCode/Json/JsonFile/funcConfig.json");
|
||
|
// if (funcConfig_file.open(QIODevice::ReadOnly)) {
|
||
|
// qDebug() << "success to open funcConfig.json";
|
||
|
// QByteArray data = funcConfig_file.readAll();
|
||
|
// // 输出文件内容,检查是否正确读取
|
||
|
// //qDebug() << "funcConfig_file content:" << data;
|
||
|
// QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
// if (!doc.isNull()) {
|
||
|
// if (doc.isArray()) {
|
||
|
// funcJsonConfig = doc.array();
|
||
|
// qDebug() << "funcJsonConfig JSON array size:" << funcJsonConfig.size();
|
||
|
// }
|
||
|
// else {
|
||
|
// qDebug() << "funcJsonConfig JSON document is not an array!";
|
||
|
// }
|
||
|
// }
|
||
|
// else {
|
||
|
// qDebug() << "Failed to parse funcJsonConfig JSON document!";
|
||
|
// }
|
||
|
// funcConfig_file.close();
|
||
|
// }
|
||
|
// else {
|
||
|
// qDebug() << "Failed to open funcConfig.json";
|
||
|
// }
|
||
|
// return funcJsonConfig;
|
||
|
//}
|
||
|
|
||
|
QJsonArray readJson_frontDevInfo()
|
||
|
{
|
||
|
QJsonArray frontDevInfo;
|
||
|
QFile frontDevInfo_file("./SourceCode/Json/JsonFile/frontDevInfo.json");
|
||
|
if (frontDevInfo_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open frontDevInfo.json";
|
||
|
QByteArray data = frontDevInfo_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "funcConfig_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
frontDevInfo = doc.array();
|
||
|
qDebug() << "frontDevInfo JSON array size:" << frontDevInfo.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "frontDevInfo JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse frontDevInfo JSON document!";
|
||
|
}
|
||
|
frontDevInfo_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open frontDevInfo.json";
|
||
|
}
|
||
|
return frontDevInfo;
|
||
|
}
|
||
|
|
||
|
QJsonArray readJson_backDevInfo()
|
||
|
{
|
||
|
QJsonArray backDevInfo;
|
||
|
QFile backDevInfo_file("./SourceCode/Json/JsonFile/backDevInfo.json");
|
||
|
if (backDevInfo_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open backDevInfo.json";
|
||
|
QByteArray data = backDevInfo_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "funcConfig_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
backDevInfo = doc.array();
|
||
|
qDebug() << "backDevInfo JSON array size:" << backDevInfo.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "backDevInfo JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse backDevInfo JSON document!";
|
||
|
}
|
||
|
backDevInfo_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open backDevInfo.json";
|
||
|
}
|
||
|
return backDevInfo;
|
||
|
}
|
||
|
|
||
|
QJsonArray readJson_getPic()
|
||
|
{
|
||
|
QJsonArray getPicJson;
|
||
|
QFile getPic_file("./SourceCode/Json/JsonFile/getPic.json");
|
||
|
if (getPic_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open getPic.json";
|
||
|
QByteArray data = getPic_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "funcConfig_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
getPicJson = doc.array();
|
||
|
qDebug() << "getPic JSON array size:" << getPicJson.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "getPic JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse getPic JSON document!";
|
||
|
}
|
||
|
getPic_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open getPic.json";
|
||
|
}
|
||
|
return getPicJson;
|
||
|
}
|
||
|
|
||
|
QJsonArray readJson_getVideo()
|
||
|
{
|
||
|
QJsonArray getVideoJson;
|
||
|
QFile getVideo_file("./SourceCode/Json/JsonFile/getVideo.json");
|
||
|
if (getVideo_file.open(QIODevice::ReadOnly)) {
|
||
|
qDebug() << "success to open getVideo.json";
|
||
|
QByteArray data = getVideo_file.readAll();
|
||
|
// 输出文件内容,检查是否正确读取
|
||
|
//qDebug() << "funcConfig_file content:" << data;
|
||
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||
|
if (!doc.isNull()) {
|
||
|
if (doc.isArray()) {
|
||
|
getVideoJson = doc.array();
|
||
|
qDebug() << "getVideo JSON array size:" << getVideoJson.size();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "getVideo JSON document is not an array!";
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to parse getVideo JSON document!";
|
||
|
}
|
||
|
getVideo_file.close();
|
||
|
}
|
||
|
else {
|
||
|
qDebug() << "Failed to open getVideo.json";
|
||
|
}
|
||
|
return getVideoJson;
|
||
|
}
|