Simple loop to extract json of any value type
Solved
General and Desktop
-
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(); }
-
F Fitndex-developer has marked this topic as solved on