Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A suggestion to QJson related classes...
Forum Updated to NodeBB v4.3 + New Features

A suggestion to QJson related classes...

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 932 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kimi Arthur
    wrote on last edited by
    #1

    Typically I write the following to retrieve data from a json document:

    data["query"].toObject()["test"].toArray()[1]

    This is great, but is quite "textful". I believe the following will be better code:

    data["query"]["test"][1]

    which removes all the type conversion part.

    And I believe this is possible with the current settings. Because we have methods like isArray, isObject etc, the framework actually knows the internal type of the QJsonValue, so we can return the value accordingly, like:

    QJsonValue QJsonValue::operator[](int i)
    {
    if (this->isArray())
    return this->toArray()[i];
    }

    QJsonValue QJsonValue::operator[](QString s)
    {
    if (this->isObject())
    return this->toObject()[s];
    }

    And this will simplify the written code quite a lot!

    Any suggestions?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I'm not using QJson*, so I don't feel strongly either way. Your proposal looks very much like 2D array, which might be confusing.

      In any case, Qt developers rarely visit this forum (save for several exception). If you want to be heard by people who make Qt happen, write to "Development Mailing List":http://lists.qt-project.org/mailman/listinfo.

      (Z(:^

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved