6 #ifndef SWIFT_MISC_JSON_H
7 #define SWIFT_MISC_JSON_H
14 #include <QJsonDocument>
15 #include <QJsonObject>
17 #include <QJsonValueRef>
18 #include <QStringList>
70 std::pair<QString, const ENUM &> value)
76 std::enable_if_t<std::is_enum_v<ENUM>,
QJsonObject> &
79 json[value.first] =
QJsonValue(
static_cast<int>(value.second));
96 json[value.first] =
QJsonValue(
static_cast<int>(value.second));
103 template <
class ENUM>
106 value =
static_cast<ENUM
>(json.
toInt());
112 template <
class ENUM>
121 template <
class ENUM,
typename = std::enable_if_t<std::is_enum_v<ENUM>>>
124 value =
static_cast<ENUM
>(json.toInt());
130 template <
class ENUM>
139 template <
class FIRST,
class SECOND>
140 QJsonValueRef
operator>>(QJsonValueRef json, std::pair<FIRST, SECOND> &pair)
148 template <
class FIRST,
class SECOND>
189 const std::pair<swift::misc::CExplicitLatin1String, const int &> &value);
191 const std::pair<swift::misc::CExplicitLatin1String, const qint16 &> &value);
193 operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const qlonglong &> &value);
195 const std::pair<swift::misc::CExplicitLatin1String, const uint &> &value);
197 operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const qulonglong &> &value);
199 const std::pair<swift::misc::CExplicitLatin1String, const QString &> &value);
201 operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const std::string &> &value);
203 operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const QStringList &> &value);
205 const std::pair<swift::misc::CExplicitLatin1String, const double &> &value);
207 const std::pair<swift::misc::CExplicitLatin1String, const bool &> &value);
209 operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const QDateTime &> &value);
211 const std::pair<swift::misc::CExplicitLatin1String, const QPixmap &> &value);
213 operator<<(
QJsonObject &json,
const std::pair<swift::misc::CExplicitLatin1String, const QByteArray &> &value);
223 namespace swift::misc::json
318 if (jsonString.
isEmpty()) {
return false; }
319 object.convertFromJson(jsonString, acceptCacheFormat);
329 const QString jsonString(
object.toJsonString());
330 if (jsonString.
isEmpty()) {
return false; }
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.
std::enable_if_t< std::is_enum_v< ENUM >, QJsonObject > & operator<<(QJsonObject &json, std::pair< QString, const ENUM & > value)
Specialized JSON serialization for enum.
QJsonObject & appendJsonObject(QJsonObject &target, const QJsonObject &toBeAppended)
Append to first JSON object (concatenate)
QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat)
JSON Object from string.
QJsonArray jsonArrayFromString(const QString &json)
JSON Array from string.
SWIFT_MISC_EXPORT const QJsonValue & operator>>(const QJsonValue &json, int &value)
Streaming operators for QJsonValue (to value)
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.