Can't read file more than n bytes
-
Hey guys,
I'm trying to parse a json file, however for some unknown reason it fails to read it completely. I can read 29276 bytes, then it suddenly stops. It doesn't matter if I try to save the content as QByteArray or QString. The qDebug() line is simply not executed, all code after works...
http://pastebin.com/raw/eQ9v0AyT
QFile dataFile("data.json"); if(dataFile.open(QIODevice::ReadOnly)) { QByteArray ba = dataFile.readAll(); qDebug() << "File Content: " << ba; dataFile.close(); }
Any help is appreciated. Thanks in advance!
-
@m.sue sorry, typo. didn't mean dataFile.count(). "qDebug() << ba.count();" does work fine and give proper output.
When reading more than my limit, for example with "QByteArray ba = dataFile.read(29277)", ba.count() also does work. So yes, the reading works.
Adding the following returns "true". So the doc is also empty when using the ByteArray.
QJsonDocument doc = QJsonDocument::fromJson(ba); qDebug() << doc.isEmpty();
-
@m.sue said in Can't read file more than n bytes:
That may be restriction in the buffer length of the (place where you view the) qDebug output.
Maybe just view it in two parts will show you the results:qDebug() << ba.right(25000); qDebug() << ba.mid(25000); //+/- 1
This actually works for output. I've used:
qDebug() << "AAA"; qDebug() << ba.left(dataFile.size()/2); qDebug() << "BBB"; qDebug() << ba.right(dataFile.size()/2); qDebug() << "CCC";
Anyway, the buffer also seems to be there when doing:
QJsonDocument doc = QJsonDocument::fromJson(ba);
If I split the file, the json is invalid and can't be put with fromJson anymore. This seems to be a very weird limitation?!
-
Hi,
Do you have any special character in your .json file ?