|
KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
|
|
#include <jsonhelper.h>
Static Public Member Functions | |
| static bool | tryGetString (const QJsonObject &object, const QString &key, QString &value) |
| Try to read a string value from a JSON object. | |
| static bool | tryGetObject (const QJsonObject &object, const QString &key, QJsonObject &value) |
| Try to read a nested JSON object from a JSON object. | |
| static bool | tryGetArray (const QJsonObject &object, const QString &key, QJsonArray &value) |
| Try to read a JSON array from a JSON object. | |
| 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 bool | tryGetDouble (const QJsonObject &object, const QString &key, qreal &value) |
| Try to read a double from a JSON object. | |
| static bool | tryGetBool (const QJsonObject &object, const QString &key, bool &value) |
| Try to read a boolean from a JSON object. | |
| static QString | toIndented (const QByteArray &json) |
| Format a compact JSON byte array as an indented human-readable string. | |
| static QJsonArray | toJsonArray (const QStringList &value) |
| Convert a QStringList to a QJsonArray. | |
| static QStringList | toStringList (const QJsonArray &value) |
| Convert a QJsonArray of strings to a QStringList. | |
| static QStringList | fromJsonArray (const QJsonArray &value) |
| Convert a QJsonArray of strings to a QStringList (alias for toStringList). | |
| static void | appendToArray (QJsonArray &destArray, const QJsonArray &sourceArray) |
| Append all elements from sourceArray into destArray. | |
| static QJsonValue | uuidOrNull (const QUuid &uuid) |
| Return a UUID as a JSON string, or JSON null if the UUID is null. | |
| static QJsonValue | stringOrNull (const QString &value) |
| Return a string as a JSON string, or JSON null if the string is empty. | |
| static QJsonValue | intOrNull (const QVariant &value) |
| Return a QVariant integer as a JSON integer, or JSON null if the variant is null. | |
| static QJsonValue | doubleOrNull (const QVariant &value) |
| Return a QVariant double as a JSON double, or JSON null if the variant 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 QJsonValue | arrayOrNull (const QStringList &value) |
| Return a QStringList as a JSON array, or JSON null if the list is empty. | |
| 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 QVariant | doubleStringOrNull (const QJsonValue &value, int precision=6) |
| Parse a double from a JSON string value, or return an invalid QVariant if null. | |
Some static helper methods for QJson where the C# tryGet() model is desired.
Stephen Punak, May 16 2020
Static helper methods for reading and writing QJsonObject values safely.
Provides tryGet-style methods that return false rather than throwing when a key is absent or the wrong type, plus convenience conversions between Qt and JSON types.
Definition at line 22 of file jsonhelper.h.
|
static |
Append all elements from sourceArray into destArray.
| destArray | Destination array to append to |
| sourceArray | Source array whose elements are appended |
|
static |
Return a QStringList as a JSON array, or JSON null if the list is empty.
| value | String list to serialize |
|
static |
Extract a double QVariant from a JSON value, or an invalid QVariant if null.
| value | JSON value to read |
|
inlinestatic |
Return a QVariant double as a JSON double, or JSON null if the variant is null.
| value | Variant holding a double |
Definition at line 149 of file jsonhelper.h.
|
static |
Parse a double from a JSON string value, or return an invalid QVariant if null.
| value | JSON string value to parse |
| precision | Precision hint (default 6) |
|
static |
Return a QVariant double formatted as a JSON string, or JSON null if the variant is null.
| value | Variant holding a double |
| precision | Number of decimal places (default 6) |
|
inlinestatic |
Convert a QJsonArray of strings to a QStringList (alias for toStringList).
| value | JSON array to convert |
Definition at line 114 of file jsonhelper.h.
|
inlinestatic |
Extract an integer QVariant from a JSON value, or an invalid QVariant if null.
| value | JSON value to read |
Definition at line 171 of file jsonhelper.h.
|
inlinestatic |
Return a QVariant integer as a JSON integer, or JSON null if the variant is null.
| value | Variant holding an integer |
Definition at line 142 of file jsonhelper.h.
|
inlinestatic |
Return a string as a JSON string, or JSON null if the string is empty.
| value | String to serialize |
Definition at line 135 of file jsonhelper.h.
|
static |
Format a compact JSON byte array as an indented human-readable string.
| json | Compact JSON bytes |
|
static |
Convert a QStringList to a QJsonArray.
| value | String list to convert |
|
static |
Convert a QJsonArray of strings to a QStringList.
| value | JSON array to convert |
|
static |
Try to read a JSON array from a JSON object.
| object | Source JSON object |
| key | Key to look up |
| value | Output receiving the array |
|
static |
Try to read a boolean from a JSON object.
| object | Source JSON object |
| key | Key to look up |
| value | Output receiving the boolean |
|
static |
Try to read a double from a JSON object.
| object | Source JSON object |
| key | Key to look up |
| value | Output receiving the double |
|
static |
Try to read a 32-bit signed integer from a JSON object.
| object | Source JSON object |
| key | Key to look up |
| value | Output receiving the integer |
|
static |
Try to read a nested JSON object from a JSON object.
| object | Source JSON object |
| key | Key to look up |
| value | Output receiving the nested object |
|
static |
Try to read a string value from a JSON object.
| object | Source JSON object |
| key | Key to look up |
| value | Output receiving the string |
|
static |
Try to read a 32-bit unsigned integer from a JSON object.
| object | Source JSON object |
| key | Key to look up |
| value | Output receiving the unsigned integer |
|
inlinestatic |
Return a UUID as a JSON string, or JSON null if the UUID is null.
| uuid | UUID to serialize |
Definition at line 128 of file jsonhelper.h.