Results 1 to 3 of 3

Thread: writing to previously existing json file using Qt5.3

  1. #1
    Join Date
    Jun 2014
    Posts
    2
    Qt products
    Qt5

    Default writing to previously existing json file using Qt5.3

    I am using QT 5.3. I have read various materials present online describing how to write json file,but no content describes it systematically and stepwise.

    It would be really helpful if someone can explain the stepwise process of writing a json file in simple language since i am new to qt.

    In my case i have a json file that already exists "LOM.json" with some content.How do i add new data to this.
    Qt Code:
    1. { "LOM": [
    2. { "LOM ID": 1,
    3. "Source": "Open Internet",
    4. "Content": "Complete Reference Java.pdf",
    5. "Difficulty Level": "Hard",
    6. "Type": "Text",
    7. "Length": "Long",
    8. "Topic-Proficiency":
    9. [
    10. { "Topic": "Programming", "Proficiency": "E2" },
    11. { "Topic": "Java", "Proficiency": "E3" }
    12. ]
    13. },
    14. { "LOM ID": 2,
    15. "Source": "Open Internet",
    16. "Content": "www.LatexTutorial.com",
    17. "Difficulty Level": "Medium",
    18. "Type": "WebCourse",
    19. "Length": "Medium",
    20. "Topic-Proficiency":
    21. [
    22. { "Topic": "Latex", "Proficiency": "E2" }
    23. ]
    24. }
    25. ]
    26. }
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: writing to previously existing json file using Qt5.3

    Read in Qt doc about this example.

  3. #3
    Join Date
    Jun 2014
    Posts
    2
    Qt products
    Qt5

    Default Re: writing to previously existing json file using Qt5.3

    Actually the problem is...here in my example each object has a key-value pair "Topic-Proficiency" whose value is of type array of objects.When i try to insert QJsonObject type object to QJsonArray,it is not allowed since QJsonArray can only have QJsonValue type value. Thats's why i am not able to insert ,multiple QJsonObject to QJsonArray.


    Added after 1 56 minutes:


    I finally got it done.
    Actually the mistake was that while declaring the QJsonObject and QjsonArray,i was declaring them as pointer type that's why it was not allowing to insert qjsonobject to qjsonarray.
    As far as writing to already existing json file is concerned,firstly the file is to be opened and content is to be read in qjsonarray or object.Next the changes to be done are appended to the read data(in qjson object or qjsonarray) and finally the new value is inserted to the read document by removing the previous one.
    Thanks for the help.
    Last edited by NS_19; 13th June 2014 at 06:53.

Similar Threads

  1. reading JSON file in Qt5
    By LZAntal in forum Newbie
    Replies: 4
    Last Post: 21st August 2017, 20:44
  2. Replies: 0
    Last Post: 31st May 2013, 14:40
  3. Using external Json file in QML
    By Kelteseth in forum Qt Quick
    Replies: 0
    Last Post: 30th November 2012, 17:08
  4. Replies: 3
    Last Post: 3rd August 2010, 13:12
  5. Replies: 25
    Last Post: 15th January 2006, 00:53

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.