Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-34112

Add [] operator to QJsonValue

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.1.1
    • Core: Other
    • None
    • a7823b487808a869d4bdc3ff20fddb04967211e1

    Description

      QJsonValue is the return type by QJsonObject["key"] and QJsonArray[1].
      If QJsonValue supports [] operator, then value retrieval sequence will be more easily chained.

      Say,

      the json contained in the QJsonObject p,

      {
          "a": [
              {"t1": "t2"},
              {"t3": "t4"}
          ],
          "b": {
              "c": "d"
          }
      }
      
      

      If I want to get the "t4" value, I need to write,

      p["a"].toArray()[1].toObject()["t3"].toString()
      

      If the [] operator is added to QJsonValue, I can write it as,

      p["a"][1]["t3"].toString()
      

      which will be significantly shorter and easier to understand.

      Also, it should be possible to implement since the parameter type passed to [] operator is different, one is int and one is string. And the return types can be the same QJsonValue. So there should be syntax problem.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vestbo Tor Arne Vestbø
            kimi arthur Kimi Arthur
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes