Results 1 to 3 of 3

Thread: QScriptEngine Printout to String as JSON

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Unhappy QScriptEngine Printout to String as JSON

    I'm using QScriptEngine to create JSON object like this.

    Qt Code:
    1. QStringList aApplicatoinIds;
    2. QStringList aDisplaynames;
    3. QStringList aIconPaths;
    4. QList<int> aMessageCounts;
    5. aApplicatoinIds.append("app.test.com");
    6. aDisplaynames.append("testi appi");
    7. aIconPaths.append("c:\\data\\icon2.bmp");
    8. aMessageCounts.append(2);
    9. aApplicatoinIds.append("app.demo.com");
    10. aDisplaynames.append("demo appi");
    11. aIconPaths.append("c:\\data\\demo.bmp");
    12. aMessageCounts.append(4);
    13. int size = aApplicatoinIds.count();
    14.  
    15.  
    16. QScriptEngine engine;
    17. QScriptValue list = engine.newArray(size);
    18.  
    19. for (int i=0; i < size; i++)
    20. {
    21. QScriptValue application = engine.newObject();
    22. application.setProperty(JSON_APPLICATIONID,aApplicatoinIds.at(0));
    23. application.setProperty(JSON_DISPLAYNAME,aDisplaynames.at(0));
    24. application.setProperty(JSON_ICONPATH,aIconPaths.at(0));
    25. application.setProperty(JSON_MESSAGES,aMessageCounts.at(0));
    26. list.setProperty(i,application);
    27. LOGTXT("++");
    28. }
    29.  
    30. QScriptValue notify = engine.newObject();
    31. notify.setProperty(JSON_LIST,list);
    32.  
    33. QScriptValue globalObj = engine.newObject();
    34. globalObj.setProperty(JSON_NOTIFY,notify);
    35.  
    36. 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:

    Qt Code:
    1. {
    2. "notify":{
    3. "list": [
    4. {
    5. "applicationid":"test.app.com",
    6. "displayname":"testing",
    7. "iconpath":"c:\data\test.img",
    8. "messages":5
    9. }
    10. ]}
    11. }
    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.

  2. #2
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QScriptEngine Printout to String as JSON

    I'd take a look at QJSON
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  3. #3

    Default Re: QScriptEngine Printout to String as JSON

    That's the first thing I found about JSON handling in Qt, but the problem is that it's under license and I don't want to go publishing my own codes so it's not an option for me.

    Any other ideas? Anyway to get the QScriptEngine exporing the whole JSON as string?

Similar Threads

  1. parsing JSON format
    By Raajesh in forum Qt Programming
    Replies: 5
    Last Post: 12th September 2010, 00:40
  2. Replies: 0
    Last Post: 16th May 2010, 18:53
  3. Build json, how to?
    By martinn in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2010, 16:19
  4. QScriptEngine
    By coderbob in forum Qt Programming
    Replies: 10
    Last Post: 25th January 2010, 17:12
  5. json: eval
    By mickey in forum General Programming
    Replies: 3
    Last Post: 17th January 2008, 20:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.