本文整理汇总了C++中qjson::Serializer::setIndentMode方法的典型用法代码示例。如果您正苦于以下问题:C++ Serializer::setIndentMode方法的具体用法?C++ Serializer::setIndentMode怎么用?C++ Serializer::setIndentMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qjson::Serializer
的用法示例。
在下文中一共展示了Serializer::setIndentMode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toJson
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: Serialize
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: printJSON
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: main
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;
}
示例5: main
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: save
/**
* 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: save
/**
* 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: save
/**
* 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;
}