Indexing unnamed QJsonDocument in Qt < 5.10

29 Views Asked by At

Given unnamed JSON document:

[
    {
    },
    {
    },
 ]

Qt 5.10+ has operator[] for QJsonDocument, so we can address any of them by index:

json_doc[1];

How does one do the same in older versions of Qt?

1

There are 1 best solutions below

0
On

In your particular example the Json document is represented by a Json array. You might get it like:

if (document.isArray() {
    auto a = document.array();
    // TODO: check the array size before
    auto v = a[0];
}