Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
5.12
-
None
-
Windows 7, Windows 10, both 32 and 64 bit.
Description
On Windows systems with Qt 5.12 (various minor versions up to the most current), JSON arrays are being parsed into QJsonArray differently, depending on whether we use Qt for and with MinGW 7.3.0 or Qt for MSVC with clang-cl.
With MSVC/clang-cl, the outcome is as one would expect: A JSON array results in a QJsonArray with one entry for each object in the array. An empty JSON array results in an empty QJsonArray.
With MinGW, a JSON array always results in a QJsonArray with exactly one entry, which is a QJsonArray itself. That "inner" QJsonArray then contains the actual array entries (if any).
Example code:
static void testJsonArray() { const QByteArray jsonInput("{\"emptyArray\": []}"); const QJsonDocument doc { QJsonDocument::fromJson(jsonInput) }; const QJsonObject docObj { doc.object() }; const QJsonArray emptyArray { docObj.value("emptyArray").toArray() }; // MSVC/clang-cl: emptyArray is empty. // MinGW: emptyArray contains one subarray (!) which is empty. qDebug() << "empty array:" << emptyArray.count() << "entries:"; for (const QJsonValue& e : emptyArray) { qDebug() << "\t" << e; } }
Output with MSVC/clang-cl:
empty array: 0 entries:
Output with MinGW:
empty array: 1 entries: QJsonValue(array, QJsonArray([]))