Take the 2-minute tour ×

I have a QString of JSON-encoded dictionaries. Is there a simple way to convert them to a list of QHashes? I've looked at this post Best JSON parser for Qt?, but haven't been able to get a valid QHash out (says it's empty).

"[{ 'var' : 'xres', 'name' : 'Image Width', 'type' : 'int', 'min' : 1, 'max' : 4096},{ 'var' : 'yres', 'name' : 'Image Height', 'type' : 'int', 'min' : 1, 'max' : 4096}]"

and I'd like them in something like QList<QHash<QString,QVariant>>.


QScriptValue sc;
QScriptEngine engine;
sc = engine.evaluate(atts); // In new versions it may need to look like engine.evaluate("(" + QString(result) + ")");

QVariantList attsList;
qScriptValueToSequence(sc, attsList);

foreach (QVariant item, attsList) {
    //std::cout << item.typeName() << std::endl;
    QMap<QString,QVariant> attribute = item.toMap();
    attribute["name"].toString() // etc.
share|improve this question
please post the code you tried so that people can look at it and hopefully fix it. –  Mat Jun 24 '11 at 4:48
add comment

1 Answer

up vote 1 down vote accepted

If you're using QScriptEngine (or QJson) to do the parsing, this puts the properties into a QMap rather than a QHash.

It's easy enough to convert between the two, but it won't be done automatically.

share|improve this answer
add comment

Your Answer


