prevent json file read error
This commit is contained in:
parent
e10b5b1d39
commit
a0e3339bf7
|
@ -81,7 +81,9 @@ void AutolinkManager::load()
|
|||
#endif
|
||||
}
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QByteArray content = file.readAll();
|
||||
QByteArray content = file.readAll().trimmed();
|
||||
if (content.isEmpty())
|
||||
return;
|
||||
QJsonDocument doc(QJsonDocument::fromJson(content));
|
||||
fromJson(doc.array());
|
||||
file.close();
|
||||
|
|
|
@ -82,7 +82,9 @@ void CodeSnippetsManager::loadSnippets()
|
|||
return;
|
||||
}
|
||||
|
||||
QByteArray json = file.readAll();
|
||||
QByteArray json = file.readAll().trimmed();
|
||||
if (json.isEmpty())
|
||||
return;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
|
|
|
@ -68,7 +68,9 @@ PColorScheme ColorScheme::load(const QString &filename)
|
|||
qDebug()<<QObject::tr("Can't open file '%1' for read").arg(file.fileName());
|
||||
return PColorScheme();
|
||||
}
|
||||
QByteArray content = file.readAll();
|
||||
QByteArray content = file.readAll().trimmed();
|
||||
if (content.isEmpty())
|
||||
return PColorScheme();
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(content,&error);
|
||||
if (error.error!=QJsonParseError::NoError) {
|
||||
|
|
|
@ -381,7 +381,9 @@ QList<PIconSet> IconsManager::listIconSets()
|
|||
pSet->displayName = pSet->name;
|
||||
QFile infoFile(includeTrailingPathDelimiter(fileInfo.absoluteFilePath())+"info.json");
|
||||
if (infoFile.exists() && infoFile.open(QFile::ReadOnly)) {
|
||||
QByteArray content = infoFile.readAll();
|
||||
QByteArray content = infoFile.readAll().trimmed();
|
||||
if (content.isEmpty())
|
||||
return result;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc(QJsonDocument::fromJson(content,&error));
|
||||
if (error.error == QJsonParseError::NoError) {
|
||||
|
|
|
@ -1928,7 +1928,9 @@ QHash<QString, PProjectEditorLayout> Project::loadLayout()
|
|||
QFile file(jsonFilename);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return layouts;
|
||||
QByteArray content = file.readAll();
|
||||
QByteArray content = file.readAll().trimmed();
|
||||
if (content.isEmpty())
|
||||
return layouts;
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument doc(QJsonDocument::fromJson(content,&parseError));
|
||||
file.close();
|
||||
|
|
|
@ -46,7 +46,9 @@ void ShortcutManager::load()
|
|||
return;
|
||||
}
|
||||
|
||||
QByteArray json = file.readAll();
|
||||
QByteArray json = file.readAll().trimmed();
|
||||
if (json.isEmpty())
|
||||
return;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
|
|
|
@ -42,7 +42,9 @@ void SymbolUsageManager::load()
|
|||
tr("Can't open symbol usage file '%1' for read.")
|
||||
.arg(filename));
|
||||
}
|
||||
QByteArray contents = file.readAll();
|
||||
QByteArray contents = file.readAll().trimmed();
|
||||
if (contents.isEmpty())
|
||||
return;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(contents,&error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
|
|
|
@ -204,7 +204,9 @@ AppTheme::AppTheme(const QString &filename, ThemeType type, QObject *parent):QOb
|
|||
.arg(filename));
|
||||
}
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QByteArray content = file.readAll();
|
||||
QByteArray content = file.readAll().trimmed();
|
||||
if (content.isEmpty())
|
||||
return;
|
||||
QJsonObject obj;
|
||||
|
||||
switch (type) {
|
||||
|
|
|
@ -69,7 +69,9 @@ void ToolsManager::load()
|
|||
return;
|
||||
}
|
||||
|
||||
QByteArray json = file.readAll();
|
||||
QByteArray json = file.readAll().trimmed();
|
||||
if (json.isEmpty())
|
||||
return;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(json,&error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
|
|
|
@ -96,8 +96,11 @@ PVisitHistory VisitHistoryManager::doLoad(const QString &filename, qint64 criter
|
|||
QFile file(filename);
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
return pHistory;
|
||||
QByteArray content = file.readAll().trimmed();
|
||||
if (content.isEmpty())
|
||||
return pHistory;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc=QJsonDocument::fromJson(file.readAll(),&error);
|
||||
QJsonDocument doc=QJsonDocument::fromJson(content, &error);
|
||||
if (error.error!=QJsonParseError::NoError)
|
||||
return pHistory;
|
||||
bool ok;
|
||||
|
|
|
@ -174,7 +174,9 @@ void OJProblemSetModel::loadFromFile(const QString &fileName, int& currentIndex)
|
|||
{
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QByteArray content = file.readAll();
|
||||
QByteArray content = file.readAll().trimmed();
|
||||
if (content.isEmpty())
|
||||
return;
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc(QJsonDocument::fromJson(content,&error));
|
||||
if (error.error!=QJsonParseError::NoError) {
|
||||
|
|
Loading…
Reference in New Issue