-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
374 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
"dd/MM/yyyy hh:mm", | ||
"yyyy/MM/dd hh:mm:ss", | ||
"yyyy.MM.dd_hh:mm:ss", | ||
"yyyy/MM/dd hh_mm_ss" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "json_utils.h" | ||
|
||
#include <QJsonObject> | ||
#include <QJsonArray> | ||
#include <QJsonDocument> | ||
#include <QJsonValue> | ||
#include <QFile> | ||
#include <QDebug> | ||
#include <QGuiApplication> | ||
#include <QDir> | ||
|
||
|
||
namespace jsn { | ||
|
||
bool getJsonObjectFromFile(const QString& path, | ||
QJsonObject& object) { | ||
QFile file(path); | ||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
qDebug() << "File can't be opened!" << path; | ||
return false; | ||
}; | ||
QByteArray data = file.readAll(); | ||
QJsonParseError errorPtr; | ||
object = QJsonDocument::fromJson(data, &errorPtr).object(); | ||
if (object.isEmpty()) { | ||
qDebug() << "JSON IS EMPTY: " << errorPtr.errorString(); | ||
return false; | ||
} | ||
file.close(); | ||
|
||
return true; | ||
} | ||
|
||
bool getJsonArrayFromFile(const QString& path, | ||
QJsonArray& object) { | ||
QFile file(path); | ||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
qDebug() << "File can't be opened!" << path; | ||
return false; | ||
}; | ||
QByteArray data = file.readAll(); | ||
QJsonParseError errorPtr; | ||
object = QJsonDocument::fromJson(data, &errorPtr).array(); | ||
if (object.isEmpty()) { | ||
qDebug() << "JSON IS EMPTY: " << errorPtr.errorString(); | ||
return false; | ||
} | ||
file.close(); | ||
return true; | ||
} | ||
|
||
bool saveJsonObjectToFile(const QString& path, | ||
const QJsonObject& json_object, | ||
QJsonDocument::JsonFormat format) { | ||
QFile file(path); | ||
if (!file.open(QIODevice::WriteOnly)) | ||
return false; | ||
auto json_doc = QJsonDocument(json_object).toJson(format); | ||
auto result = file.write(json_doc); | ||
file.close(); | ||
if (result == -1) | ||
return false; | ||
else | ||
return true; | ||
} | ||
|
||
bool saveJsonArrayToFile(const QString& path, | ||
const QJsonArray& json_object, | ||
QJsonDocument::JsonFormat format) { | ||
QFile file(path); | ||
if (!file.open(QIODevice::WriteOnly)) | ||
return false; | ||
auto json_doc = QJsonDocument(json_object).toJson(format); | ||
auto result = file.write(json_doc); | ||
file.close(); | ||
if (result == -1) | ||
return false; | ||
else | ||
return true; | ||
} | ||
|
||
} // end jsn namespace |
Oops, something went wrong.