Skip to content

Instantly share code, notes, and snippets.

@bradley-curran
Created November 7, 2012 05:17
Show Gist options
  • Save bradley-curran/4029684 to your computer and use it in GitHub Desktop.
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
#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;
}
#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