1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Add wrapper to handle JSON parsing w.r.t. Qt version

This commit is contained in:
Uwe L. Korn 2014-04-12 08:42:55 +01:00
parent 3982d5fb65
commit b7bf5b6241
2 changed files with 22 additions and 0 deletions

View File

@ -54,8 +54,12 @@
#include <QStringList>
#include <QTranslator>
// Qt version specific includes
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
#include <QUrlQuery>
#include <QJsonDocument>
#else
#include <qjson/parser.h>
#endif
#ifdef Q_OS_WIN
@ -842,6 +846,21 @@ compareVersionStrings( const QString& first, const QString& second )
}
QVariant
parseJson( const QByteArray& jsonData, bool* ok )
{
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson( jsonData, &error );
*ok = ( error.error == QJsonParseError::NoError );
return doc.toVariant();
#else
QJson::Parser p;
return p.parse( jsonData, ok );
#endif
}
void
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
{

View File

@ -207,6 +207,9 @@ namespace TomahawkUtils
* Qt4 / Qt5 compatibility layer
*/
/* QJson */
DLLEXPORT QVariant parseJson( const QByteArray& jsonData, bool* ok = 0 );
/* QUrl */
DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );