Permalink
Browse files

Merge pull request #13 from federico-lox/master

QHash support
  • Loading branch information...
Eeli Reilin
Eeli Reilin committed May 2, 2012
2 parents 63a1e5c + 977e63f commit 64d9ef66e497047547eb9f6e0c29287cdb3b4b9a
Showing with 24 additions and 0 deletions.
  1. +24 −0 json.cpp
View
@@ -131,6 +131,30 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
str = "[ " + join( values, ", " ) + " ]";
}
+ else if(data.type() == QVariant::Hash) // variant is a hash?
+ {
+ const QVariantHash vhash = data.toHash();
+ QHashIterator<QString, QVariant> it( vhash );
+ str = "{ ";
+ QList<QByteArray> pairs;
+
+ while(it.hasNext())
+ {
+ it.next();
+ QByteArray serializedValue = serialize(it.value());
+
+ if(serializedValue.isNull())
+ {
+ success = false;
+ break;
+ }
+
+ pairs << sanitizeString(it.key()).toUtf8() + " : " + serializedValue;
+ }
+
+ str += join(pairs, ", ");
+ str += " }";
+ }
else if(data.type() == QVariant::Map) // variant is a map?
{
const QVariantMap vmap = data.toMap();

0 comments on commit 64d9ef6

Please sign in to comment.