Results 1 to 3 of 3

Thread: How I can create below Json Format in Qt ?

  1. #1
    Join Date
    Jun 2015
    Posts
    86
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How I can create below Json Format in Qt ?

    I have an example, but not getting how I can create it.

    Qt Code:
    1. {
    2. "Version" : "1.0",
    3. "tap" : { },
    4. "notation" : { },
    5. "definition" :
    6. [
    7. {
    8. "tag":1,
    9. "Name" : "view1"
    10. }
    11.  
    12. {
    13. "tag":2,
    14. "Name" : "view2"
    15. }
    16. ]
    17. "images" :
    18. {
    19. "File" : "image.png",
    20. "Index" : 0,
    21. "Properties" : [ "black", "bold"]
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Please give me a sample example which helps me to create this.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,396
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How I can create below Json Format in Qt ?

    I would say something like this

    Qt Code:
    1. QJsonObject mainObject;
    2. mainObject.insert("Version", "1.0");
    3. mainObjecti.insert("tap", QJsonObject());
    4. mainObjecti.insert("notation", QJsonObject());
    5.  
    6. QJsonObject definition1;
    7. definition1.insert("tag", 1);
    8. definition1.insert("Name", "view1");
    9. QJsonObject definition2;
    10. definition2.insert("tag", 2);
    11. definition2.insert("Name", "view2");
    12.  
    13. QJsonArray definition;
    14. defintion.append(definition1);
    15. defintion.append(definition2);
    16. mainObject.insert("definition", definition);
    17.  
    18. QJsonObject images;
    19. images.insert("File", "image.png");
    20. images.insert("Index", 0);
    21. images.insert("Properties", QJsonArray{"black", "bold"});
    22. mainObject.insert("images", images);
    23.  
    24. QJsonDocument document(mainObject);
    25. QByteArray jsonData = document.toJson(QJsonDocument::Indented);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    npatil15 (11th July 2019)

  4. #3
    Join Date
    Jun 2015
    Posts
    86
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How I can create below Json Format in Qt ?

    Thanks it works well.
    Last edited by npatil15; 11th July 2019 at 07:14.

Similar Threads

  1. Need suggestion for to write QString to JSON format
    By wagmare in forum Qt Programming
    Replies: 1
    Last Post: 17th September 2014, 09:16
  2. Replies: 2
    Last Post: 3rd June 2011, 07:39
  3. Replies: 5
    Last Post: 1st June 2011, 08:28
  4. Replies: 1
    Last Post: 14th January 2011, 11:57
  5. parsing JSON format
    By Raajesh in forum Qt Programming
    Replies: 5
    Last Post: 11th September 2010, 23:40

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.