- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonutils.cpp
More file actions
Latest commit
22 lines (18 loc) · 477 Bytes
/
Copy pathjsonutils.cpp
File metadata and controls
22 lines (18 loc) · 477 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include"jsonutils.h"
#include<QFile>
#include<QJsonDocument>
#include<QDebug>
QJsonObject loadJsonFile(const QString &path)
{
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Failed to open JSON:" << path;
return {};
}
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
if (!doc.isObject()) {
qWarning() << "Invalid JSON format:" << path;
return {};
}
return doc.object();
}