Looking at the documentation for QJsonDocument, you can read the file in QByteArray, and then do the following: -
Then use the function on the QJsonDocument to retrieve the top-level object ...
if(doc.isObject()) { QJsonObject obj = doc.object(); QJsonObject::iterator itr = obj.find("id"); if(itr == obj.end()) { // object not found. } // do something with the found object... }
QJsonObject also has a value () function, so instead of using an iterator and calling find, you can just call: -
QJsonValue val = obj.value("id");
Disclaimer: I present this code after I just read the Qt documentation, so don't just copy and paste this, but consider it more pseudo-code. You may need to edit it a bit, but hope this helps.
source share