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:
parent
3982d5fb65
commit
b7bf5b6241
@ -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 )
|
||||
{
|
||||
|
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user