33#ifndef _QX_SERIALIZE_QJSON_QMULTIHASH_H_
34#define _QX_SERIALIZE_QJSON_QMULTIHASH_H_
47#include <QtCore/qjsonvalue.h>
48#include <QtCore/qjsonobject.h>
49#include <QtCore/qjsonarray.h>
50#include <QtCore/qhash.h>
59template <
typename Key,
typename Value>
62 static inline QJsonValue
toJson(
const QMultiHash<Key, Value> & t,
const QString & format)
64 QJsonArray arr; QJsonValue val;
65 QHashIterator<Key, Value> itr(t);
69 itr.next(); QJsonObject obj;
75 return QJsonValue(arr);
79template <
typename Key,
typename Value>
82 static inline qx_bool fromJson(
const QJsonValue & j, QMultiHash<Key, Value> & t,
const QString & format)
85 if (! j.isArray()) {
return qx_bool(
true); }
86 QJsonArray arr = j.toArray(); QJsonValue val; QJsonObject obj;
87 t.reserve(arr.count());
89 for (
int i = 0; i < arr.count(); i++)
91 val = arr.at(i);
if (! val.isObject()) {
continue; }
92 obj = val.toObject(); Key key; Value value;
qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QV...
qx_bool : boolean type with code and description message when an error occured
qx_bool from_json(const QJsonValue &j, T &t, const QString &format=QString())
QJsonValue to_json(const T &t, const QString &format=QString())
Root namespace for all QxOrm library features.
static qx_bool fromJson(const QJsonValue &j, QMultiHash< Key, Value > &t, const QString &format)
static QJsonValue toJson(const QMultiHash< Key, Value > &t, const QString &format)