Unsolved How to create JSON using QJsonDocument?
-
Here is a small snippet
QJsonValue value{QJsonValue::Object}; value.toObject().insert("key", "value"); QJsonDocument doc; doc.setObject(value.toObject()); std::cout << doc.toJson().toStdString();
It however outputs a blank object i.e.
{}
in console. Why is that the case? -
@ajaxcrypto said in How to create JSON using QJsonDocument?:
QJsonValue value{QJsonValue::Object}; value.toObject().insert("key", "value");
Does this alter your
QJsonValue value
? -
@JNBarchan said in How to create JSON using QJsonDocument?:
@ajaxcrypto said in How to create JSON using QJsonDocument?:
QJsonValue value{QJsonValue::Object}; value.toObject().insert("key", "value");
Does this alter your
QJsonValue value
?No.
@ajaxcrypto: Try this:
QJsonValue value{QJsonValue::Object}; QJsonObject object = value.toObject(); object.insert("key", "value"); QJsonDocument doc; doc.setObject(object); std::cout << doc.toJson().toStdString();