简体   繁体   中英

Indexing unnamed QJsonDocument in Qt < 5.10

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?

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM