///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2011-2013 Statoil ASA, Ceetron AS // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #pragma once // Json parser based on code example found on: // http://stackoverflow.com/questions/4169988/easiest-way-to-parse-json-in-qt-4-7 //#define IMPL_DUMP_TO_FILE #include #include #include #include #include #if IMPL_DUMP_TO_FILE #include #include #endif class QScriptEngine; // Encapsulate the JSON code in a namespace to avoid issues with JSON classes used in opm-parser namespace ResInsightInternalJson { class JsonReader { public: QMap decodeFile( QString filePath ); #if IMPL_DUMP_TO_FILE void dumpToFile( std::vector& points, QString filePath ); #endif }; class Json { public: Json(){}; QString encode( const QMap& map, bool prettify ); QMap decode( const QString& jsonStr ); private: QScriptValue encodeInner( const QMap& map, QScriptEngine* engine ); QMap decodeInner( QScriptValue object ); QList decodeInnerToList( QScriptValue arrayValue ); }; } // namespace ResInsightInternalJson