Results 1 to 6 of 6

Thread: Build json, how to?

  1. #1
    Join Date
    Feb 2010
    Posts
    51
    Thanks
    9
    Thanked 14 Times in 4 Posts

    Default Build json, how to?

    Hi!

    If found out from this example http://qtwiki.org/Parsing_JSON_with_...ard_QT_library how easy it was to parse json with Qt. Nice! But what if I need the other way around? I need to build json from QObject instance, how to do that?

    Thanks!

  2. #2
    Join Date
    Feb 2010
    Posts
    51
    Thanks
    9
    Thanked 14 Times in 4 Posts

    Default Re: Build json, how to?

    Anyone now how to do this?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Build json, how to?

    Iterate over properties of QObject and compose the json string based on the property name and property value converted to string (for scalar values) or lists or maps (for lists and maps).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Build json, how to?

    EDIT: Wysota got there before me.

  5. #5
    Join Date
    Feb 2010
    Posts
    51
    Thanks
    9
    Thanked 14 Times in 4 Posts

    Default Re: Build json, how to?

    Thanks for the answer! I'm quite a newbie, do you have some example code that I can take a look at, it would be very very helpful! Thanks again!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Build json, how to?

    Use QMetaObject associated with your object to query for names of static properties or use QObject::dynamicPropertyNames() for dynamic properties. Then query the object for value of each of the properties and compose a string using the json format.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. parsing JSON format
    By Raajesh in forum Qt Programming
    Replies: 5
    Last Post: 11th September 2010, 23:40
  2. Replies: 1
    Last Post: 13th January 2010, 23:35
  3. Moving from QT 4.5 shared build to QT 4.5.2 static build
    By extrakun in forum Qt Programming
    Replies: 0
    Last Post: 26th October 2009, 09:49
  4. json: eval
    By mickey in forum General Programming
    Replies: 3
    Last Post: 17th January 2008, 19:50
  5. Replies: 3
    Last Post: 28th December 2007, 11:02

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.