I've been stuck on this for a while, I'm trying to write JSON with this syntax
{
"1": {
"type": "spin",
"timeTap": 2.000,
"timeEnd": 9.600,
"beatState": 1,
"rotation": 12
},
"2": {
"type": "tap",
"timeTap": 10.800,
"beatState": 2,
"rotation": 15
} }
but I've trouble understanding the way QJson works. I'm not looking for a full answer, rather a way to understand it.
Thanks a lot.
Example:
QVariantMap object1;
object1["type"] = "spin";
object1["timeTap"] = 2.0;
object1["timeEnd"] = 9.6;
object1["beatState"] = 1;
object1["rotation"] = 12;
QVariantMap object2;
object2["type"] = "tap";
object2["timeTap"] = 10.8;
object2["beatState"] = 2;
object2["rotation"] = 15;
QVariantMap root;
root["1"] = object1;
root["2"] = object2;
qDebug() << QJsonDocument(QJsonObject::fromVariantMap(root)).toJson();
Note that QJsonDocument::fromVariant(root)
seems to work too, but in its documentation QVariant::Map
type is marked as obsolete, so I'm not sure it will work in future versions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.