Writing a json file!
Solved
General and Desktop
-
What i need it to look like
{ "Device": [ { "IPA": "studiolights", "Icon": "fa_bolt", "Name": "Studio Lights", "Status": "online", "Type": "Strip", "UVLights": false } ] }
what i have so far
QJsonObject jsonObject; jsonObject.insert("IPA", "studiolights"); jsonObject.insert("Icon", "fa_bolt"); jsonObject.insert("Name", "Studio Lights"); jsonObject.insert("Status", "online"); jsonObject.insert("Type", "Strip"); jsonObject.insert("UVLights", "false"); QJsonDocument jsonDoc; jsonDoc.setObject(jsonObject); file.write(jsonDoc.toJson()); file.close();
how to i insert the
"Device": [
? :S -
Hi,
Create a QJsonArray to contain your list of objects and then an object to contain that array.
-
got it working :) thanks @JonB and @SGaist
QJsonObject studiolights; studiolights.insert("IPA", "studiolights"); studiolights.insert("Icon", "fa_bolt"); studiolights.insert("Name", "Studio Lights"); studiolights.insert("Status", "online"); studiolights.insert("Type", "Strip"); studiolights.insert("UVLights", "false"); QJsonArray devices; devices.append(studiolights); QJsonObject obj; obj["Device"] = devices; QJsonDocument jsonDoc; jsonDoc.setObject(obj); file.write(jsonDoc.toJson()); file.close();