diff options
Diffstat (limited to 'logic/MMCJson.cpp')
-rw-r--r-- | logic/MMCJson.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/logic/MMCJson.cpp b/logic/MMCJson.cpp index 65423436..8de88b6b 100644 --- a/logic/MMCJson.cpp +++ b/logic/MMCJson.cpp @@ -1,5 +1,6 @@ #include "MMCJson.h" #include <QString> +#include <QStringList> #include <math.h> bool MMCJson::ensureBoolean(const QJsonValue val, const QString what) @@ -11,7 +12,7 @@ bool MMCJson::ensureBoolean(const QJsonValue val, const QString what) QJsonValue MMCJson::ensureExists(QJsonValue val, const QString what) { - if(val.isNull()) + if(val.isUndefined() || val.isUndefined()) throw JSONValidationError(what + " does not exist"); return val; } @@ -59,3 +60,24 @@ QString MMCJson::ensureString(const QJsonValue val, const QString what) return val.toString(); } +void MMCJson::writeString(QJsonObject &to, QString key, QString value) +{ + if(value.size()) + { + to.insert(key, value); + } +} + +void MMCJson::writeStringList(QJsonObject &to, QString key, QStringList values) +{ + if(values.size()) + { + QJsonArray array; + for(auto value: values) + { + array.append(value); + } + to.insert(key, array); + } +} + |