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

Simple loop to extract json of any value type

Scheduled Pinned Locked Moved Solved General and Desktop
jsonextract datajson reply
1 Posts 1 Posters 168 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.
  • F Offline
    F Offline
    Fitndex-developer
    wrote on 26 Feb 2023, 00:19 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
    • F Fitndex-developer has marked this topic as solved on 26 Feb 2023, 00:23

    1/1

    26 Feb 2023, 00:19

    • Login

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