@KroMignon said in Parsing incomplete json array on QTcpSocket readyRead() , unterminated string:
@rifky said in Parsing incomplete json array on QTcpSocket readyRead() , unterminated string:
solved , maybe it's not a great solution, but it solves my problem
As @jsulm has written, the best way is to declare a class member to store temporary value.
Then, according to your example, you are search a string with is between [].
So one solution would be something like this:
class SocksUpdata : public QObject
{
Q_OBJECT
private:
QByteArray _buffer;
...
};
QByteArray SocksUpdata::getData()
{
_buffer.append(tcpSocketUpdata->readAll());
int idx = _buffer.indexOf('[');
if(_buffer[0] != '[' && idx > 0)
{
_buffer.remove(0, idx);
}
idx = _buffer.indexOf(']');
if(_buffer[0] == '[' && idx > 0)
{
QByteArray byte_json = _buffer.left(idx+1);
_buffer.remove(0, idx+1);
QJsonParseError parseErr;
QJsonDocument doc = QJsonDocument::fromJson(byte_json, &parseErr);
if(parseError_2.error != QJsonParseError::NoError)
{
emit setJsonInvalid(this->epoch, byte_json);
}
else
{
// do your stuff
}
}
}
thx alot sir, it's working .
i got little bit confuse using QbyteArray, i'm trying to made my code working with QHash wich can storing QByteArray, thx for help i'm realy appriciate that :)