Results 1 to 10 of 10

Thread: Traversing QVariantMap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default Re: Traversing QVariantMap

    Thanks, yes it seems I was trying to read the reply twice and that's why I was getting that effect.

    I will try your approaches with isMap and toMap. Just to again highlight what kind of problem I had,
    for example the entry in the JSON file is smth like this:
    "Key: "result" Value: QVariant(QVariantMap, QMap(("code", QVariant(qlonglong,
    1) ) ) )"
    after printing them as you suggested.

    Now, what I am actually interested in, is the value of "code" which is 1. So, when I try to run
    the following command:
    Qt Code:
    1. if (results.contains("code"))
    2. qDebug()<<"***code***: "<<results.value("code");
    To copy to clipboard, switch view to plain text mode 
    it returns an empty string. Which seems to be due to the fact which we mentioned .....

    So, you recommend to use isMatp and etc. right??? I will see that approach now, because my JSON
    file has a loft of such nested QVariantMaps -- thanks again.

    ps. Do you have maybe some samples on the web site or know links which show how to
    (recursively, as it appears now) parse the whole JSON file ??? Thanks.

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

    Default Re: Traversing QVariantMap

    Quote Originally Posted by ggdev001 View Post
    ps. Do you have maybe some samples on the web site or know links which show how to
    (recursively, as it appears now) parse the whole JSON file ??? Thanks.
    Qt5 can directly read JSON data and parse it to QVariant or QJsonDocument, for Qt4 there is either the QJson project or you can use QtScript to parse a json string to a javascript object.
    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.


  3. #3
    Join Date
    Feb 2013
    Posts
    50
    Thanks
    5

    Default Re: Traversing QVariantMap

    Hi, I am using https://developer.blackberry.com/cas...with_json.html, because
    I am doing BlackBerry 10 development.
    Yes, indeed I think JasonDataAcess class in my case returns QVariant as the root element of the JSON data; this QVariant on the other
    hand contains a QVariantMap in my case.
    My problem starts that this QVariantMap has many nested elements inside (including other QVariantMaps), and I want to be able
    to retrieve values associated with the keys, of these QVariantMaps. that's why it would be helpful for me to have some tutorial or code sample on it... thanks once again.

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

    Default Re: Traversing QVariantMap

    I already gave you everything you need. Provided that you know what "recursively" means, you should have no problems in accessing any data in the map that you need.
    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. Replies: 0
    Last Post: 10th December 2011, 11:17
  2. Replies: 0
    Last Post: 16th May 2010, 17:53
  3. Traversing QTableView
    By junxuan in forum Qt Programming
    Replies: 2
    Last Post: 1st August 2009, 18:44
  4. QVariant, QVariantMap, and QFileInfoList
    By themolecule in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 07:00
  5. Traversing a QTreeWidget
    By johnny_sparx in forum Newbie
    Replies: 5
    Last Post: 26th March 2006, 09:32

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
  •  
Qt is a trademark of The Qt Company.