server player req: parse malformed json
ATM10 server seems to send a extra json object after the default response, that we need to cut off. Signed-off-by: Tayou <git@tayou.org> Co-authored-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@@ -80,7 +80,18 @@ void McClient::parseResponse()
|
||||
Q_UNUSED(readVarInt(m_resp)); // json length
|
||||
|
||||
// 'resp' should now be the JSON string
|
||||
QJsonDocument doc = QJsonDocument::fromJson(m_resp);
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(m_resp, &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
QByteArray validJson = m_resp.left(parseError.offset);
|
||||
doc = QJsonDocument::fromJson(validJson, &parseError);
|
||||
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
qDebug() << "Failed to parse JSON:" << parseError.errorString();
|
||||
emitFail(parseError.errorString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
emitSucceed(doc.object());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user