14#include "kanoopcommon.h"
32 static bool tryGetString(
const QJsonObject&
object,
const QString& key, QString& value);
41 static bool tryGetObject(
const QJsonObject&
object,
const QString& key, QJsonObject& value);
50 static bool tryGetArray(
const QJsonObject&
object,
const QString& key, QJsonArray& value);
59 static bool tryGetInt32(
const QJsonObject&
object,
const QString& key, qint32& value);
68 static bool tryGetUInt32(
const QJsonObject&
object,
const QString& key, quint32& value);
77 static bool tryGetDouble(
const QJsonObject&
object,
const QString& key, qreal& value);
86 static bool tryGetBool(
const QJsonObject&
object,
const QString& key,
bool& value);
114 static QStringList
fromJsonArray(
const QJsonArray& value) {
return toStringList(value); }
121 static void appendToArray(QJsonArray& destArray,
const QJsonArray& sourceArray);
128 static QJsonValue
uuidOrNull(
const QUuid& uuid) {
return uuid.isNull() ? QJsonValue() : uuid.toString(QUuid::WithoutBraces); }
135 static QJsonValue
stringOrNull(
const QString& value) {
return value.isEmpty() ? QJsonValue() : value; }
142 static QJsonValue
intOrNull(
const QVariant& value) {
return value.isNull() ? QJsonValue() : value.toInt(); }
149 static QJsonValue
doubleOrNull(
const QVariant& value) {
return value.isNull() ? QJsonValue() : value.toDouble(); }
171 static QVariant
intOrNull(
const QJsonValue& value) { QVariant result;
return value.isNull() ? result : value.toInt(); }
static QJsonValue intOrNull(const QVariant &value)
Return a QVariant integer as a JSON integer, or JSON null if the variant is null.
static void appendToArray(QJsonArray &destArray, const QJsonArray &sourceArray)
Append all elements from sourceArray into destArray.
static QVariant intOrNull(const QJsonValue &value)
Extract an integer QVariant from a JSON value, or an invalid QVariant if null.
static QVariant doubleOrNull(const QJsonValue &value)
Extract a double QVariant from a JSON value, or an invalid QVariant if null.
static bool tryGetArray(const QJsonObject &object, const QString &key, QJsonArray &value)
Try to read a JSON array from a JSON object.
static bool tryGetString(const QJsonObject &object, const QString &key, QString &value)
Try to read a string value from a JSON object.
static bool tryGetDouble(const QJsonObject &object, const QString &key, qreal &value)
Try to read a double from a JSON object.
static QJsonValue stringOrNull(const QString &value)
Return a string as a JSON string, or JSON null if the string is empty.
static QJsonValue doubleOrNull(const QVariant &value)
Return a QVariant double as a JSON double, or JSON null if the variant is null.
static QStringList fromJsonArray(const QJsonArray &value)
Convert a QJsonArray of strings to a QStringList (alias for toStringList).
static bool tryGetInt32(const QJsonObject &object, const QString &key, qint32 &value)
Try to read a 32-bit signed integer from a JSON object.
static bool tryGetUInt32(const QJsonObject &object, const QString &key, quint32 &value)
Try to read a 32-bit unsigned integer from a JSON object.
static QVariant doubleStringOrNull(const QJsonValue &value, int precision=6)
Parse a double from a JSON string value, or return an invalid QVariant if null.
static QJsonArray toJsonArray(const QStringList &value)
Convert a QStringList to a QJsonArray.
static bool tryGetObject(const QJsonObject &object, const QString &key, QJsonObject &value)
Try to read a nested JSON object from a JSON object.
static QString toIndented(const QByteArray &json)
Format a compact JSON byte array as an indented human-readable string.
static bool tryGetBool(const QJsonObject &object, const QString &key, bool &value)
Try to read a boolean from a JSON object.
static QJsonValue arrayOrNull(const QStringList &value)
Return a QStringList as a JSON array, or JSON null if the list is empty.
static QJsonValue uuidOrNull(const QUuid &uuid)
Return a UUID as a JSON string, or JSON null if the UUID is null.
static QJsonValue doubleStringOrNull(const QVariant &value, int precision=6)
Return a QVariant double formatted as a JSON string, or JSON null if the variant is null.
static QStringList toStringList(const QJsonArray &value)
Convert a QJsonArray of strings to a QStringList.