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. Simple loop to extract json of any value type
Forum Updated to NodeBB v4.3 + New Features

Simple loop to extract json of any value type

Scheduled Pinned Locked Moved Solved General and Desktop
jsonextract datajson reply
1 Posts 1 Posters 198 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.
  • Fitndex-developerF Offline
    Fitndex-developerF Offline
    Fitndex-developer
    wrote on last edited by
    #1

    Re: |HELP| : How to extract Data from Json file ?
    In the post referenced, the solution only works if the json value is holding a “string”. In my case the database returns some string, numbers, and timestamps. Here is what works with just about any variable type; even json values which contain another json object.

    QByteArray currentByteArray = rep->readAll();
    QJsonDocument json = QJsonDocument::fromJson(currentByteArray);
    QJsonArray jArr = json.array();
    QStringList nameArr;
    QList<int> ageArr;
    QList<double> adubArr;
    QStringList timestampArr;
    for(auto jObj : jArr){
    nameArr << QVariant(jObj.toObject().value(“name”).toVariant()).toString();
                ageArr<< QVariant(jObj.toObject().value(“age”).toVariant()).toInt();
    	    adubArr << QVariant(jObj.toObject().value(“adub”).toVariant()).toDouble();
    
               //in my case the timestamp returns another json object with another set of json values of which one is named date
               timestampArr << jObj.toObject().value("timestamp").toObject().value("date").toString();
    
            }
    
    1 Reply Last reply
    0
    • Fitndex-developerF Fitndex-developer has marked this topic as solved on

    • Login

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