2025-12-08 13:25:02 +01:00
|
|
|
#ifndef JSONPARSER_H
|
|
|
|
|
#define JSONPARSER_H
|
|
|
|
|
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
|
|
class QJsonObject;
|
|
|
|
|
class QString;
|
|
|
|
|
class QByteArray;
|
|
|
|
|
class QJsonArray;
|
|
|
|
|
|
2026-02-02 16:13:44 +01:00
|
|
|
typedef QMap<int, QVariant> ModelItemValues;
|
2026-01-04 17:48:27 +01:00
|
|
|
|
2025-12-29 13:03:09 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
2025-12-08 13:25:02 +01:00
|
|
|
class JsonParser {
|
|
|
|
|
public:
|
2026-01-04 17:48:27 +01:00
|
|
|
static QList<ModelItemValues> toItemValuesList(const QByteArray& jsonData,
|
2026-02-02 16:13:44 +01:00
|
|
|
const QString& rootValueName = "");
|
2026-01-04 17:48:27 +01:00
|
|
|
static QByteArray itemValuesListToJson(const QList<ModelItemValues>& itemValuesList,
|
2025-12-31 10:39:32 +01:00
|
|
|
const QString& objectName = "");
|
2026-03-01 10:59:34 +01:00
|
|
|
static QJsonObject itemValuesToJsonObject(const ModelItemValues& itemValues);
|
2025-12-08 13:25:02 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit JsonParser();
|
|
|
|
|
|
2026-02-03 11:55:43 +01:00
|
|
|
static QJsonArray extractItemArray(const QJsonDocument& doc, const QString& objectName);
|
2026-01-04 17:48:27 +01:00
|
|
|
static ModelItemValues jsonObjectToItemValues(const QJsonObject& itemJsonObject);
|
2025-12-29 13:03:09 +01:00
|
|
|
|
|
|
|
|
static pair<int, QVariant> getKeyValuePair(const QJsonObject& itemJsonObject, const int role);
|
2026-03-01 11:11:46 +01:00
|
|
|
|
|
|
|
|
static QJsonValue extractJsonValue(const ModelItemValues& itemValues, const int role);
|
2025-12-08 13:25:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // JSONPARSER_H
|