#pragma once #include "dbcorelib_global.h" #include #include #include #include template T getJson(const QJsonDocument &document); template<> QJsonDocument DBCORELIB_EXPORT getJson(const QJsonDocument &document); template<> QJsonObject DBCORELIB_EXPORT getJson(const QJsonDocument &document); template<> QJsonArray DBCORELIB_EXPORT getJson(const QJsonDocument &document); template T getJson(const QByteArray &byteArray); template T getJson(QIODevice &device); template T getJson(const QString &filename); template T getJson(const QByteArray &byteArray) { QJsonParseError error; auto document = QJsonDocument::fromJson(byteArray, &error); if(error.error != QJsonParseError::NoError) throw std::runtime_error(QString("Could not parse json: %0").arg(error.errorString()).toStdString()); return getJson(document); } template T getJson(QIODevice &device) { return getJson(device.readAll()); } template T getJson(const QString &filename) { QFile file(filename); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) throw std::runtime_error(QString("Could not open json file %0: %1").arg(filename, file.errorString()).toStdString()); return getJson(file); }