I'm using QScriptEngine to create JSON object like this.
QList<int> aMessageCounts;
aApplicatoinIds.append("app.test.com");
aDisplaynames.append("testi appi");
aIconPaths.append("c:\\data\\icon2.bmp");
aMessageCounts.append(2);
aApplicatoinIds.append("app.demo.com");
aDisplaynames.append("demo appi");
aIconPaths.append("c:\\data\\demo.bmp");
aMessageCounts.append(4);
int size = aApplicatoinIds.count();
QScriptEngine engine;
QScriptValue list = engine.newArray(size);
for (int i=0; i < size; i++)
{
QScriptValue application = engine.newObject();
application.setProperty(JSON_APPLICATIONID,aApplicatoinIds.at(0));
application.setProperty(JSON_DISPLAYNAME,aDisplaynames.at(0));
application.setProperty(JSON_ICONPATH,aIconPaths.at(0));
application.setProperty(JSON_MESSAGES,aMessageCounts.at(0));
list.setProperty(i,application);
LOGTXT("++");
}
QScriptValue notify = engine.newObject();
notify.setProperty(JSON_LIST,list);
QScriptValue globalObj = engine.newObject();
globalObj.setProperty(JSON_NOTIFY,notify);
engine.setGlobalObject(globalObj);
QStringList aApplicatoinIds;
QStringList aDisplaynames;
QStringList aIconPaths;
QList<int> aMessageCounts;
aApplicatoinIds.append("app.test.com");
aDisplaynames.append("testi appi");
aIconPaths.append("c:\\data\\icon2.bmp");
aMessageCounts.append(2);
aApplicatoinIds.append("app.demo.com");
aDisplaynames.append("demo appi");
aIconPaths.append("c:\\data\\demo.bmp");
aMessageCounts.append(4);
int size = aApplicatoinIds.count();
QScriptEngine engine;
QScriptValue list = engine.newArray(size);
for (int i=0; i < size; i++)
{
QScriptValue application = engine.newObject();
application.setProperty(JSON_APPLICATIONID,aApplicatoinIds.at(0));
application.setProperty(JSON_DISPLAYNAME,aDisplaynames.at(0));
application.setProperty(JSON_ICONPATH,aIconPaths.at(0));
application.setProperty(JSON_MESSAGES,aMessageCounts.at(0));
list.setProperty(i,application);
LOGTXT("++");
}
QScriptValue notify = engine.newObject();
notify.setProperty(JSON_LIST,list);
QScriptValue globalObj = engine.newObject();
globalObj.setProperty(JSON_NOTIFY,notify);
engine.setGlobalObject(globalObj);
To copy to clipboard, switch view to plain text mode
Now, I'¨m trying to get engine output as JSON in QString like this:
{
"notify":{
"list": [
{
"applicationid":"test.app.com",
"displayname":"testing",
"iconpath":"c:\data\test.img",
"messages":5
}
]}
}
{
"notify":{
"list": [
{
"applicationid":"test.app.com",
"displayname":"testing",
"iconpath":"c:\data\test.img",
"messages":5
}
]}
}
To copy to clipboard, switch view to plain text mode
How to do it?
Or if you can show some code example how to create JSON string, I'm listening.
Bookmarks