Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended
-
I have a strange issue working with Json...
I receive an encrypted byte array from a network source, the length varies but currently under testing it is an array of either about 100 characters or a bit over 20 000 characters. I output the recieved byte array (after decryption) and the resulting json document to a log file to keep track (see in the code below)
When I run a debug in Qt Creator (version 4.5.1, Based on Qt 5.10.1 (MSVC 2015, 32 bit)) everything works fine, but when I build an installation file and install it I get this really weird issue. The short array (about 100 characters) still works as it should, but the long one doesn't. The output in the log file of the "tmpTestJson" is just empty. I can see that all characters are received, but for some reason the conversion to Json document isn't working.
Can a Json character array be too long? Why do I get an issue in the installed version but not in the debug version? Any help is appreciated.
This is the code where i have the issue:
QByteArray configData = reply->readAll(); AESCryptoUtil aes; QByteArray decryptedConfigData = aes.Decrypt(QByteArray::fromBase64(configData)); emit log(QString("received data: " + decryptedConfigData)); QJsonDocument configJsonDoc = QJsonDocument::fromJson(decryptedConfigData); QString tmpTestJson = configJsonDoc.toJson(QJsonDocument::Indented); log(QString("Json Document: " + tmpTestJson));
-
@DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:
QByteArray configData = reply->readAll();
are you 100% sure that at the time you call
reply->readAll()
you really have received all data (=valid JSON data)?! -
@raven-worx I get the entire bytearray (including the finishing brackets) when "decryptedConfigData" is printed, but nothing when "tmpTestJson". As far as I know that means that I get all the data and should have valid Json data. The printed "decryptedConfigData" is identical when running in the debugger and the installed version.
-
@DanBar
What is the output of the following?QJsonParseError jsonError; QJsonDocument configJsonDoc = QJsonDocument::fromJson(decryptedConfigData, &jsonError); if( jsonError.error != QJsonParseError::NoError ) log( QString("Json error: %1").arg(jsonError.errorString()) ); else if( configJsonDoc .isNull() ) log( "Null JsonDocument );
-
-
@DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:
"Json error: illegal number"
what does that mean?possibly an integer/decimal value beginning with
0
(e.g.propertyName: 01234
)? unless it's an octal value. -
@raven-worx There are many values that are 0 and a few values that are decimal, are those allowed while running in Qtcreator but not as an installed program?
a sample part of the json:
"name": "Test 4",
"valueA": 180,
"valueB": "",
"valueC": 9,
"valueD": 1,
"valueE": 0.8869204367,
"valueF": 1500,
"valueG": "C",
"valueH": 0,
"valueI": "16d29c44-3d0941",
"valueJ": "1392fa45-68c943",
"valueK": "2018-08-06 09:07:29", -
@DanBar
Hi
You you also output
http://doc.qt.io/qt-5/qjsonparseerror.html#offset-var
as it gives a clue where in the file it gets error. -
@DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:
There are many values that are 0 and a few values that are decimal, are those allowed while running in Qtcreator but not as an installed program?
a sample part of the json:
"name": "Test 4",
"valueA": 180,
"valueB": "",
"valueC": 9,
"valueD": 1,
"valueE": 0.8869204367,
"valueF": 1500,
"valueG": "C",
"valueH": 0,
"valueI": "16d29c44-3d0941",
"valueJ": "1392fa45-68c943",
"valueK": "2018-08-06 09:07:29",none of those values should raise this error as far i see.
I was talking about decimals bigger than0
. So 0 is of course a valid decimal value, but02934
notBut you havent answered my first question. Are you sure you already received the full data before you start to parse the JSON data?!
-
Hi,
How long is the long array that makes things fail ?
See QTBUG-47629 for a limitation on QJsonObject's size.
-
Thank you all for your help!
I was able to solve this issue, but the problem wasn't in the Json itself. I got a tip a tip from my colleague to check the .dll-files in the installation folder, and I noticed that they weren't entirely up to date. When I replaced them with the correct version of .dll-files the issue was solved. I still don't know exactly what caused this issue between the versions (version 5.9 and 5.10) but the issue is solved so I'm happy in either case.
Again, thanks!
-
@DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:
installation folder
Which installation folder do you mean? Qt? Your app?