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. How to search spesific element in JSON file?
Forum Updated to NodeBB v4.3 + New Features

How to search spesific element in JSON file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 221 Views
  • 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.
  • D Offline
    D Offline
    deleted286
    wrote on last edited by
    #1

    Here is my Json file.

    {
       "A":[
          {
             "GPS":[
                {
                   "GPS ID":[
                      "integer",
                      "0"
                   ],
                   "GPS Mod":[
                      "integer",
                      "1"
                   ],
                   "GPS Utc":[
                      "float",
                      "2"
                   ],
                   "GPS Latitude":[
                      "float",
                      "3"
                   ],
                   "GPS Longitude":[
                      "float",
                      "4"
                   ]
      
                }
             ]
    

    I've read it like that:

        ```
    
    QByteArray data = file.readAll();
            QJsonDocument doc = QJsonDocument::fromJson(data);
    
            QJsonObject root = doc.object();
            QJsonArray tlmtArray = root.value("Telemetri Verileri").toArray();
    
            for(int i=0; i<tlmtArray.size(); i++)
            {
                QJsonObject obj = tlmtArray.at(i).toObject();
              // qDebug() << "bakalm okudumu" << obj;
               QString a= tlmtArray.at(i).toString();
          }
    
    
    How can I print the all values which contains "float"
    JonBJ 1 Reply Last reply
    0
    • D deleted286

      Here is my Json file.

      {
         "A":[
            {
               "GPS":[
                  {
                     "GPS ID":[
                        "integer",
                        "0"
                     ],
                     "GPS Mod":[
                        "integer",
                        "1"
                     ],
                     "GPS Utc":[
                        "float",
                        "2"
                     ],
                     "GPS Latitude":[
                        "float",
                        "3"
                     ],
                     "GPS Longitude":[
                        "float",
                        "4"
                     ]
        
                  }
               ]
      

      I've read it like that:

          ```
      
      QByteArray data = file.readAll();
              QJsonDocument doc = QJsonDocument::fromJson(data);
      
              QJsonObject root = doc.object();
              QJsonArray tlmtArray = root.value("Telemetri Verileri").toArray();
      
              for(int i=0; i<tlmtArray.size(); i++)
              {
                  QJsonObject obj = tlmtArray.at(i).toObject();
                // qDebug() << "bakalm okudumu" << obj;
                 QString a= tlmtArray.at(i).toString();
            }
      
      
      How can I print the all values which contains "float"
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @suslucoder
      GPS holds an array of objects. (It only seems to contain one object in the array, but that's what it's the JSON.) Go through each key in the object. If its value is an array (all of yours are), array[0] is the "type", so see if array[0] == "float", and output array[1] if it does.

      1 Reply Last reply
      1

      • Login

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