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

QJsonObject returns "not accessible" when the item type is string

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.15.2
    • Core: Object Model
    • None
    • Linux/X11

    Description

      in this code the qjsonobject works perfectely except when item value is string.

      lets suppose that we hae an external file called test.json.

       

       test.json:

       

      {
      "foo":

      { "item1": 4999, ",tem2": "489sss651584", "item3": true, "item4":[ "tab0", "tab1", "tab2" ] }

      }

       

       
      QString val;
      QFile file;
      file.setFileName("test.json");
      file.open(QIODevice::ReadOnly | QIODevice::Text);
      val = file.readAll();
      file.close();
      QJsonDocument d = QJsonDocument::fromJson(val.toUtf8());
      QJsonObject sett2 = d.object();
      QJsonValue functions = sett2.value(QString("foo"));
      QJsonObject item = functions.toObject();
      QJsonValue item1 = item["item1"];
      QJsonValue item2 = item["item2"];
      QJsonValue item3 = item["item3"];
      QJsonArray item4 = item["irwm4"].toArray();

      ///// output:
      item1 = integer = 4999
      item2 = not accessible
      item3 = bool = true
      item4 = array = [....]

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            mohamed.elleuch Mohamed Elleuch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes