6#ifndef SWIFT_MISC_JSON_H
7#define SWIFT_MISC_JSON_H
14#include <QJsonDocument>
17#include <QJsonValueRef>
71 json.insert(value.first,
QJsonValue(
static_cast<int>(value.second)));
76 requires(std::is_enum_v<ENUM>)
78 json[value.first] =
QJsonValue(
static_cast<int>(value.second));
95 json[value.first] =
QJsonValue(
static_cast<int>(value.second));
105 value =
static_cast<ENUM
>(json.toInt());
121QJsonValueRef
operator>>(QJsonValueRef json, ENUM &value)
requires(std::is_enum_v<ENUM>)
123 value =
static_cast<ENUM
>(json.toInt());
138template <
class FIRST,
class SECOND>
139QJsonValueRef
operator>>(QJsonValueRef json, std::pair<FIRST, SECOND> &pair)
147template <
class FIRST,
class SECOND>
188 const std::pair<swift::misc::CExplicitLatin1String, const int &> &value);
190 const std::pair<swift::misc::CExplicitLatin1String, const qint16 &> &value);
192operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const qlonglong &> &value);
194 const std::pair<swift::misc::CExplicitLatin1String, const uint &> &value);
196operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const qulonglong &> &value);
198 const std::pair<swift::misc::CExplicitLatin1String, const QString &> &value);
200operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const std::string &> &value);
202operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const QStringList &> &value);
204 const std::pair<swift::misc::CExplicitLatin1String, const double &> &value);
206 const std::pair<swift::misc::CExplicitLatin1String, const bool &> &value);
208operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const QDateTime &> &value);
210 const std::pair<swift::misc::CExplicitLatin1String, const QPixmap &> &value);
212operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const QByteArray &> &value);
222namespace swift::misc::json
321 object.convertFromJson(jsonString, acceptCacheFormat);
331 const QString jsonString(
object.toJsonString());
static bool writeStringToFile(const QString &content, const QString &fileNameAndPath)
Write string to text file.
static QString readFileToString(const QString &fileNameAndPath)
Read file into string.
QString stringFromJsonObject(const QJsonObject &jsonObject, QJsonDocument::JsonFormat format)
JSON Object from string.
QJsonObject & appendJsonObject(QJsonObject &target, const QJsonObject &toBeAppended)
Append to first JSON object (concatenate).
QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat)
JSON Object from string.
SWIFT_MISC_EXPORT const QJsonValue & operator>>(const QJsonValue &json, int &value)
Streaming operators for QJsonValue (to value).
QJsonObject & operator<<(QJsonObject &json, std::pair< QString, const ENUM & > value)
Specialized JSON serialization for enum.
QJsonArray jsonArrayFromString(const QString &json)
JSON Array from string.
bool loadFromJsonFile(T &object, const QString &fileNameAndPath, bool acceptCacheFormat=false)
Load JSON file and init by that.
bool saveToJsonFile(const T &object, const QString &fileNameAndPath)
Save to JSON file.
QJsonValue first() const const
QJsonObject::iterator insert(QLatin1StringView key, const QJsonValue &value)
QJsonArray toArray() const const
int toInt(int defaultValue) const const
bool isEmpty() const const
Simple literal type containing a single QLatin1String.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.