From 43ac06ca988ef99556bceade39b1b615123947a5 Mon Sep 17 00:00:00 2001 From: sigurdp Date: Tue, 18 Sep 2018 15:33:56 +0200 Subject: [PATCH] #3344 HoloLens export: Allow for more human-readable JSON text output --- ApplicationCode/FileInterface/RifJsonEncodeDecode.cpp | 11 +++++++++-- ApplicationCode/FileInterface/RifJsonEncodeDecode.h | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ApplicationCode/FileInterface/RifJsonEncodeDecode.cpp b/ApplicationCode/FileInterface/RifJsonEncodeDecode.cpp index 99ddfcacfb..6b6871f3ac 100644 --- a/ApplicationCode/FileInterface/RifJsonEncodeDecode.cpp +++ b/ApplicationCode/FileInterface/RifJsonEncodeDecode.cpp @@ -60,10 +60,17 @@ void JsonReader::dumpToFile(std::vector& points, QString filePath) #endif -QString Json::encode(const QMap &map) +QString Json::encode(const QMap& map, bool prettify) { QScriptEngine engine; - engine.evaluate("function toString() { return JSON.stringify(this) }"); + if (prettify) + { + engine.evaluate("function toString() { return JSON.stringify(this, null, ' ') }"); + } + else + { + engine.evaluate("function toString() { return JSON.stringify(this) }"); + } QScriptValue toString = engine.globalObject().property("toString"); QScriptValue obj = encodeInner(map, &engine); diff --git a/ApplicationCode/FileInterface/RifJsonEncodeDecode.h b/ApplicationCode/FileInterface/RifJsonEncodeDecode.h index 318d09116b..c7f9919149 100644 --- a/ApplicationCode/FileInterface/RifJsonEncodeDecode.h +++ b/ApplicationCode/FileInterface/RifJsonEncodeDecode.h @@ -53,7 +53,7 @@ class Json { public: Json() {}; - QString encode(const QMap &map); + QString encode(const QMap& map, bool prettify); QMap decode(const QString &jsonStr); private: