Browse Source

Merge pull request #462 from Gelmir/webui_json

Multiple JSON parses fixes
adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
7234a93293
  1. 14
      src/webui/json.cpp

14
src/webui/json.cpp

@ -114,8 +114,11 @@ QVariantMap json::fromJson(const QString& json) {
if (!tmp.isEmpty()) couples << tmp; if (!tmp.isEmpty()) couples << tmp;
foreach (const QString &couple, couples) { foreach (const QString &couple, couples) {
QStringList parts = couple.split(":"); QStringList parts;
if (parts.size() != 2) continue; int jsonSep = couple.indexOf(":");
parts << couple.left(jsonSep);
parts << couple.mid(jsonSep + 1);
Q_ASSERT(parts.size() == 2);
QString key = parts.first(); QString key = parts.first();
if (key.startsWith("\"") && key.endsWith("\"")) { if (key.startsWith("\"") && key.endsWith("\"")) {
key = key.mid(1, key.length()-2); key = key.mid(1, key.length()-2);
@ -130,7 +133,12 @@ QVariantMap json::fromJson(const QString& json) {
if (list_val.startsWith("\"") && list_val.endsWith("\"")) { if (list_val.startsWith("\"") && list_val.endsWith("\"")) {
varlist << list_val.mid(1, list_val.length()-2).replace("\\n", "\n"); varlist << list_val.mid(1, list_val.length()-2).replace("\\n", "\n");
} else { } else {
varlist << list_val.toInt(); if (list_val.compare("false", Qt::CaseInsensitive) == 0)
varlist << false;
else if (list_val.compare("true", Qt::CaseInsensitive) == 0)
varlist << true;
else
varlist << list_val.toInt();
} }
} }
value = varlist; value = varlist;

Loading…
Cancel
Save