Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Reading and Writing JSON
Forum Updated to NodeBB v4.3 + New Features

Reading and Writing JSON

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 3 Posters 1.4k Views 3 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.
  • VineelaV Offline
    VineelaV Offline
    Vineela
    wrote on last edited by aha_1980
    #1

    this is the output of my .php link

    [
    {
    "LeaderCode": "GNL0001"
    },
    {
    "LeaderCode": "GNL0002"
    }
    ]
    

    well from this i just need to get those values "GNL0001 & GNL002" and add them to my combo box , please help me out with this.

    kshegunovK 1 Reply Last reply
    0
    • VineelaV Vineela

      this is the output of my .php link

      [
      {
      "LeaderCode": "GNL0001"
      },
      {
      "LeaderCode": "GNL0002"
      }
      ]
      

      well from this i just need to get those values "GNL0001 & GNL002" and add them to my combo box , please help me out with this.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      http://doc.qt.io/qt-5/qjsondocument.html

      Read and abide by the Qt Code of Conduct

      VineelaV 1 Reply Last reply
      2
      • kshegunovK kshegunov

        http://doc.qt.io/qt-5/qjsondocument.html

        VineelaV Offline
        VineelaV Offline
        Vineela
        wrote on last edited by
        #3

        @kshegunov thnks for your response but my question is how do I add the values to my combo box???

        kshegunovK 1 Reply Last reply
        0
        • VineelaV Vineela

          @kshegunov thnks for your response but my question is how do I add the values to my combo box???

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          Get the strings through the QJsonDocument (there are examples in the docs) and then use QComboBox::addItem to add them to the actual combo box.

          Read and abide by the Qt Code of Conduct

          VineelaV 1 Reply Last reply
          3
          • kshegunovK kshegunov

            Get the strings through the QJsonDocument (there are examples in the docs) and then use QComboBox::addItem to add them to the actual combo box.

            VineelaV Offline
            VineelaV Offline
            Vineela
            wrote on last edited by
            #5

            @kshegunov well look at this,

            void MainWindow::datainDaHouse2(QByteArray data)
            {
            //first
             qDebug()<< "Jason value" +data;
             QJsonDocument doc = QJsonDocument::fromJson(data);
                QJsonArray array = doc.array();
                QJsonObject object = array.at(0).toObject();
                QString code = object["LeaderCode"].toString();
            
                    ui->comboBox_54->insertItem(3,code);
                 //second
                    qDebug()<< "InsertCode" +code;
            }
            

            well this is my current code and my output for qDebug is,
            //first
            "Jason value<pre>[\n {\n "LeaderCode": "GNL0001"\n },\n {\n "LeaderCode": "GNL0002"\n }\n]</pre>"
            //second here where my output getting blank
            "InsertCode"
            So any suggestions ? And sorry if I'm wrong with the code ,I'm newbie .

            1 Reply Last reply
            0
            • VineelaV Offline
              VineelaV Offline
              Vineela
              wrote on last edited by
              #6

              well these are the changes I've done now its working good

              void MainWindow::datainDaHouse2(QByteArray data)
              {
              data = data.replace("<pre>", "").replace("</pre>", "");
               QJsonDocument doc = QJsonDocument::fromJson(data);
                  QJsonArray array = doc.array();
                  for(int i=0 ;i<array.size();i++){
                  QJsonObject object = array.at(i).toObject();
                  QString code = object["LeaderCode"].toString();
                  ui->comboBox_54->insertItem(1,code);
                      qDebug()<< "InsertCode" +code;
              
                  }
              }
              

              thnk u for your response :)

              1 Reply Last reply
              2
              • sankarapandiyanS Offline
                sankarapandiyanS Offline
                sankarapandiyan
                wrote on last edited by
                #7

                please mark the topic as solved

                VineelaV 1 Reply Last reply
                0
                • sankarapandiyanS sankarapandiyan

                  please mark the topic as solved

                  VineelaV Offline
                  VineelaV Offline
                  Vineela
                  wrote on last edited by
                  #8

                  @sankarapandiyan I've marked it Solved long back.

                  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