// Create an empty QJsonArray QJsonArray array; // Add some values to the array array.append("Apple"); array.append("Banana"); array.append("Orange"); // Iterate over the array and print each value for (const auto& value : array) { qDebug() << value.toString(); }
// Create a QJsonArray from a JSON string QString jsonString = "[1, 2, 3]"; QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8()); QJsonArray array = jsonDoc.array(); // Iterate over the array and print each value for (const auto& value : array) { qDebug() << value.toVariant().toInt(); }In this example, a QJsonArray is created from a JSON string using the `QJsonDocument` class. The `toVariant()` function is used to convert each value to a variant, which is then converted to an integer using the `toInt()` function. Finally, each integer value is printed to the console. Package Library: Qt 5 Core module.