Implemented error checks for parsing the JSON file
This commit is contained in:
@ -9,7 +9,17 @@ UserList loadUserList(const QString &file)
|
|||||||
{
|
{
|
||||||
QFile doc{std::filesystem::path{file.toStdString()}};
|
QFile doc{std::filesystem::path{file.toStdString()}};
|
||||||
QString fileContents = doc.readAll();
|
QString fileContents = doc.readAll();
|
||||||
QJsonDocument document = QJsonDocument::fromJson(fileContents.toUtf8());
|
|
||||||
|
QJsonParseError errors;
|
||||||
|
QJsonDocument document =
|
||||||
|
QJsonDocument::fromJson(fileContents.toUtf8(),
|
||||||
|
&errors);
|
||||||
|
|
||||||
|
if (document.isNull())
|
||||||
|
{
|
||||||
|
qDebug() << errors.errorString();
|
||||||
|
throw std::runtime_error{"Could not parse JSON file"};
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray array = document.array();
|
QJsonArray array = document.array();
|
||||||
QVector<User> container;
|
QVector<User> container;
|
||||||
|
Reference in New Issue
Block a user