{
"request":"senddata",
"datatype" : "event",
"id" : "123123",
"eventKey":"High Temperature",
"timestamp":"2017-01-13T20:15:57Z",
"eventParameters":{
"Temperature": 25,
"High Temperature": 35,
"Setpoint": 25,
}
}
For the above JSON, I've tried to use a QJsonDocument object like this:
"\"datatype\" : \"event\","
"\id\" : \"123123\","
"\"eventKey\" : \"High Temperature\","
"\timestamp\" : \"";
arr + dt;
arr += "\","
"\eventParameters\" : {"
"\"Temperature\" : 25,"
"\"High Temperature\" : 30,"
"\"Setpoint\" : 25}}";
doc = QJsonDocument::fromJson(arr);
QByteArray arr = "{\"request\" : \"senddata\","
"\"datatype\" : \"event\","
"\id\" : \"123123\","
"\"eventKey\" : \"High Temperature\","
"\timestamp\" : \"";
arr + dt;
arr += "\","
"\eventParameters\" : {"
"\"Temperature\" : 25,"
"\"High Temperature\" : 30,"
"\"Setpoint\" : 25}}";
doc = QJsonDocument::fromJson(arr);
To copy to clipboard, switch view to plain text mode
I need this because the timestamp key is a variable. I can't get this to work properly. I've also tried using the insert method with QJsonObjec more like:
json.insert("id","070707");
json.insert("request","senddata");
json.insert("datatype","event");
json.insert("eventKey","High Temperature");
json.
insert("timestamp",
QDateTime::currentDateTime().
toTimeSpec(Qt
::OffsetFromUTC).
toString(Qt
::ISODate));
...
json.insert("id","070707");
json.insert("request","senddata");
json.insert("datatype","event");
json.insert("eventKey","High Temperature");
json.insert("timestamp", QDateTime::currentDateTime().toTimeSpec(Qt::OffsetFromUTC).toString(Qt::ISODate));
...
To copy to clipboard, switch view to plain text mode
No joy here either. So my real question is how to prepare the nested JSON example for a REST type POST command. It would also be great to see a JSON array example.
Thanks,
-Rich
Bookmarks