Пример #1
0
QString Response::toJson()
{
    QVariant result = QJson::QObjectHelper::qobject2qvariant(this, QJson::QObjectHelper::Flag_None);

    QJson::Serializer s;
    s.setIndentMode(QJson::IndentCompact);
    return s.serialize(result);
}
Пример #2
0
 QByteArray Serialize(const QVariant &variant, IndentMode indentMode, bool *ok)
 {
     QJson::Serializer serializer;
     serializer.setIndentMode(static_cast<QJson::IndentMode>(indentMode));
     QByteArray data = serializer.serialize(variant, ok);
     if (ok != 0 && *ok == false)
         LogError(QString("TundraJson::Serialize: %1").arg(serializer.errorMessage()));
     return data;
 }
Пример #3
0
void JSONProtocol::printJSON(QVariantMap json) {
    QJson::Serializer serializer;
    serializer.setIndentMode(QJson::IndentCompact);

    QByteArray jsonText = serializer.serialize(json);

    io->write(jsonText);
    io->write("\n");//Print a newline to finish it

}
Пример #4
0
int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);
  QTime time;
  int   duration;

 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;

  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }
  
  Parser parser;
  bool ok;

  QFile file (filename);
  time.start();
  QVariant data = parser.parse (&file, &ok);
  duration = time.elapsed();
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "Parsing of" << filename << "took" << duration << "ms";
    if (!cmd.quiet())
      qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serializing... ";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    time.start();
    QByteArray b = serializer.serialize(data);
    duration = time.elapsed();
    qDebug() << "Serialization took:" << duration << "ms";
    if (!cmd.quiet())
     qDebug() << b;
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);
 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;


  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }
  
  Parser parser;
  bool ok;

  QFile file (filename);
  QVariant data = parser.parse (&file, &ok);
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "json object successfully converted to:";
    qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serialization output";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    QByteArray b = serializer.serialize(data);
    qDebug() << b;
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
Пример #6
0
    /**
     * Saves all settings to config file.
     * @return true if success, false otherwise
     */
    bool SettingsManager::save()
    {
        QVariantMap map = convertToMap();

        if (!QDir().mkpath(_configDir))
            return false;

        QFile f(_configPath);
        if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate))
            return false;

        bool ok;
        QJson::Serializer s;
        s.setIndentMode(QJson::IndentFull);
        s.serialize(map, &f, &ok);

        LOG_MSG("Settings saved to: " + _configPath, mongo::LL_INFO);

        return ok;
    }
Пример #7
0
    /**
     * Saves all settings to config file.
     * @return true if success, false otherwise
     */
    bool SettingsManager::save()
    {
        QVariantMap map = convertToMap();

        if (!QDir().mkpath(_configDir)) {
            LOG_MSG("ERROR: Could not create settings path: " + _configDir, mongo::logger::LogSeverity::Error());
            return false;
        }

        QFile f(_configPath);
        if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
            LOG_MSG("ERROR: Could not write settings to: " + _configPath, mongo::logger::LogSeverity::Error());
            return false;
        }

        bool ok;
        QJson::Serializer s;
        s.setIndentMode(QJson::IndentFull);
        s.serialize(map, &f, &ok);

        LOG_MSG("Settings saved to: " + _configPath, mongo::logger::LogSeverity::Info());

        return ok;
    }
Пример #8
0
    /**
     * Saves all settings to config file.
     * @return true if success, false otherwise
     */
    bool SettingsManager::save()
    {
        bool result = false;
        QVariantMap map;

        // 1. Save schema version
        map.insert("version", SchemaVersion);

        // 2. Save UUID encoding
        map.insert("uuidEncoding", _uuidEncoding);

        // 3. Save view mode
        map.insert("viewMode", _viewMode);

        // 4. Save connections
        QVariantList list;

        for(QList<ConnectionSettings *>::const_iterator it = _connections.begin();it!=_connections.end();++it) {
            QVariantMap rm = (*it)->toVariant().toMap();
            list.append(rm);
        }

        map.insert("connections", list);
        if (QDir().mkpath(_configDir))
        {
            QFile f(_configPath);
            if(f.open(QIODevice::WriteOnly | QIODevice::Truncate))
            {
                QJson::Serializer s;
                s.setIndentMode(QJson::IndentFull);
                s.serialize(map, &f, &result);
                qDebug() << "Settings saved to: " << _configPath;
            }
        }
        return result;
    }