Created
November 7, 2012 05:17
-
-
Save bradley-curran/4029684 to your computer and use it in GitHub Desktop.
Classes to help with parsing JSON data in Blackberry 10. For more information visit cascadeswithlove.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "JsonHelper.h" | |
#include <bb/data/JsonDataAccess> | |
using namespace bb::data; | |
JsonHelper::JsonHelper() | |
{ | |
} | |
JsonHelper::~JsonHelper() | |
{ | |
} | |
QVariant JsonHelper::load(const QString& filePath) | |
{ | |
JsonDataAccess jda; | |
QVariant mainList = jda.load(filePath).value<QVariant>(); | |
if (jda.hasError()) | |
{ | |
bb::data::DataAccessError error = jda.error(); | |
qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage(); | |
} | |
return mainList; | |
} | |
QVariant JsonHelper::load(const QByteArray& buffer) | |
{ | |
JsonDataAccess jda; | |
QVariant obj = jda.loadFromBuffer(buffer).value<QVariant>(); | |
if (jda.hasError()) | |
{ | |
bb::data::DataAccessError error = jda.error(); | |
qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage(); | |
} | |
return obj; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef JSONHELPER_H_ | |
#define JSONHELPER_H_ | |
#include <QVariant> | |
class JsonHelper | |
{ | |
public: | |
JsonHelper(); | |
virtual ~JsonHelper(); | |
QVariant load(const QString& filePath); | |
QVariant load(const QByteArray& buffer); | |
}; | |
#endif /* JSONHELPER_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment