本文整理汇总了C++中JsonDataAccess::hasError方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonDataAccess::hasError方法的具体用法?C++ JsonDataAccess::hasError怎么用?C++ JsonDataAccess::hasError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonDataAccess
的用法示例。
在下文中一共展示了JsonDataAccess::hasError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
bool LoginReply::parse(const QByteArray& data)
{
JsonDataAccess jsonObject;
QVariant node = jsonObject.loadFromBuffer(data);
if (jsonObject.hasError()) {
qWarning() << "error converting JSON data: " << jsonObject.error().errorMessage();
} else {
qDebug() << "before parse: " << QString(data);
QVariantMap map = node.value<QVariantMap>();
if (map["status"].toString() == "OK") {
m_status = true;
m_sessionKey = map["sessionKey"].toString();
QVariantList friendList = map["friends"].value<QVariantList>();
for (int i = 0; i < friendList.size(); i++) {
m_ppIds.append(friendList[i].toString());
}
QVariantList pinList = map["pins"].value<QVariantList>();
for (int i = 0; i < pinList.size(); i++) {
m_pins.append(pinList[i].toString());
}
return true;
}
}
return false;
}
示例2: onRequestUsers
void QBNetwork::onRequestUsers() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (reply) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
QString response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
emit error(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
emit usersReceived(response);
}
} else {
emit error("Wrong reply for request users request");
}
reply->deleteLater();
} else {
emit error("Wrong reply for request users request");
}
disconnectFromAll();
}
示例3: parse
bool GetLocationsReply::parse(const QByteArray& data)
{
JsonDataAccess jsonObject;
QVariant node = jsonObject.loadFromBuffer(data);
if (jsonObject.hasError()) {
qWarning() << "error converting JSON data: " << jsonObject.error().errorMessage();
} else {
qDebug() << "before parse: " << QString(data);
QVariantMap map = node.value<QVariantMap>();
if (map["status"].toString() == "OK") {
m_status = true;
QVariantList friendList = map["friends"].value<QVariantList>();
for (int i = 0; i < friendList.size(); i++) {
QString friendStr = friendList[i].toString();
QStringList fields = friendStr.split(",");
// if incorrect number of fields, stop parsing
if (fields.size() != 4) return false;
QString ppId = fields.at(0);
double x = fields.at(1).toDouble();
double y = fields.at(2).toDouble();
int visibility = fields.at(3).toInt();
m_friends.append(User(ppId, x, y, visibility));
}
return true;
}
}
return false;
}
示例4: onRequestSessionRegister
void QBNetwork::onRequestSessionRegister() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
emit error(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
const QVariantMap object = qtData.value<QVariantMap>();
QMapIterator<QString, QVariant> it(object);
while (it.hasNext()) {
it.next();
if (it.key() == "session") {
QVariantMap sessObject = it.value().toMap();
QMapIterator<QString, QVariant> sit(sessObject);
while (sit.hasNext()) {
sit.next();
if (sit.key() == "user_id") {
m_userId = sit.value().toString();
}
if (sit.key() == "token") {
m_token = sit.value().toString();
}
}
}
}
if (m_token != NULL) {
//register after we have session
emit sessionEstablished();
registerNewUser();
} else {
emit error("Wrong reply for register session request");
}
}
} else {
emit error("Wrong reply for register session request");
}
reply->deleteLater();
} else {
emit error("Wrong reply for register session request");
}
disconnectFromAll();
}
示例5: startLevel
void ApplicationUI::startLevel(const QVariantList &indexPath)
{
if (!m_gamePage) {
QmlDocument *qml = QmlDocument::create("asset:///Game.qml").parent(this);
qml->setContextProperty("_app", this);
m_gamePage = qml->createRootObject<Page>();
m_progressAnimation = m_gamePage->findChild<SequentialAnimation*>("progressAnimation");
}
if (indexPath.count() > 0)
m_levelIndex = indexPath[0].toInt();
else
m_levelIndex = 0; // Uhoh?
m_phase = COMPILE;
m_selectedFunction = 0;
setShouldShowFunctions(false);
setIsInFunction(-1);
Container *compileContainer = m_gamePage->findChild<Container*>("compilePhaseContainer");
compileContainer->setVisible(true);
m_gamePage->findChild<Container*>("tutorial1Container")->setProperty("state", 0);
m_gamePage->findChild<Container*>("tutorial2Container")->setProperty("state", 0);
m_gamePage->findChild<Container*>("tutorial3Container")->setProperty("state", 0);
m_gamePage->findChild<Container*>("progressBar")->setTranslationX(0);
m_gamePage->findChild<Container*>("creditsContainer")->setVisible(false);
m_gamePage->findChild<Button*>("menuButton")->setText("Continue");
m_gamePage->findChild<Container*>("menuContainer")->setVisible(false);
QVariantMap levelInfo = m_levelList->dataModel()->data(indexPath).toMap();
QString levelPath = levelInfo["level"].toString();
JsonDataAccess jda;
qDebug() << "Attempting to load " << levelPath;
QVariantMap levelData = jda.load(levelPath).toMap();
if (jda.hasError()) {
bb::data::DataAccessError error = jda.error();
qFatal("JSON loading error: %d: %s", error.errorType(), qPrintable(error.errorMessage()));
return;
} else {
qDebug() << "JSON data loaded OK!";
}
setupLevel(levelData);
setupQueue();
m_navigationPane->push(m_gamePage);
m_timer.setInterval(2000);
m_gamePage->findChild<Container*>("compileFunctionContainer")->setVisible(m_functionCount > 0);
drawSelectedFunction();
}
示例6: onRequestLogin
void QBNetwork::onRequestLogin() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
QString response;
if (reply) {
if (reply->error() == QNetworkReply::NoError) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
showError(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
const QVariantMap object = qtData.value<QVariantMap>();
QMapIterator<QString, QVariant> it(object);
while (it.hasNext()) {
it.next();
if (it.key() == "user") {
QVariantMap sessObject = it.value().toMap();
QMapIterator<QString, QVariant> sit(sessObject);
while (sit.hasNext()) {
sit.next();
if (sit.key() == "id") {
break;
}
}
}
}
}
}
} else {
if (reply->error() < 100) {
showError("Please check your internet connection");
return;
}
response =
tr("Error: %1 status: %2").arg(reply->errorString(),
reply->attribute(
QNetworkRequest::HttpStatusCodeAttribute).toString());
}
reply->deleteLater();
}
requestUsers();
}
示例7: loadSavedState
void ApplicationUI::loadSavedState()
{
QString filePath(QDir::currentPath() + "/data/levelState.json");
if (QFile::exists(filePath)) {
JsonDataAccess jda;
QVariantMap state = jda.load(filePath).toMap();
if (jda.hasError())
return;
if (state.contains("levelAvailable")) {
int levelAvailable = state["levelAvailable"].toInt();
if (levelAvailable > 0) {
setLevelAvailable(levelAvailable);
}
}
}
qDebug() << "Level available" << m_levelAvailable;
}
示例8: saveState
void ApplicationUI::saveState()
{
qDebug() << "saving state to " << QDir::currentPath() + "/data/levelState.json";
QVariantMap state;
state["levelAvailable"] = m_levelAvailable;
QFile file(QDir::currentPath() + "/data/levelState.json");
if (file.open(QIODevice::WriteOnly)) {
qDebug() << "opened file okay";
JsonDataAccess jda;
jda.save(state, &file);
if (jda.hasError()) {
qDebug("Failed to save: Json error\n");
} else {
qDebug("Saved");
}
}
}
示例9: convertQtToJson
//! [2]
void App::convertQtToJson()
{
const QString result = tr("Converting ... ");
setResult(result);
setRhsTitleAndText(mRhsDefaultTitle, "");
QString jsonBuffer;
JsonDataAccess jda;
jda.saveToBuffer(mQtData, &jsonBuffer);
if (jda.hasError()) {
const DataAccessError err = jda.error();
const QString errorMsg = tr("Error converting Qt data to JSON: %1").arg(err.errorMessage());
setResultAndState(errorMsg, QtDisplayed);
} else {
setRhsTitleAndText(tr("JSON Data from Qt"), jsonBuffer);
setResultAndState(result + tr("Success"), ReadyToWrite);
}
}
示例10: setupAlbumListModel
QVariant SongsDataModel::setupAlbumListModel()
{
// Create a new GroupDataModel; the GroupDataModel is a helper class that ListView uses for data handling.
// It uses in-memory storage so we can populate data.
// We load the GroupDataModel with help from the JsonDataAcces function, load().
JsonDataAccess jda;
QDir home = QDir::home();
QVariantMap existingAlbums = jda.load(home.absoluteFilePath("albumslist.json")).value<QVariantMap>();
if (jda.hasError()) {
bb::data::DataAccessError error = jda.error();
qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
return QVariant();
}
// Sort on region in the model so we will get different categories.
//m_albumsModel->insertList(existingAlbums);
return existingAlbums;
}
示例11: convertJsonToQt
//! [1]
void App::convertJsonToQt()
{
const QString result = tr("Converting ... ");
setResult(result);
setRhsTitleAndText(mRhsDefaultTitle, "");
setQtData (QVariant());
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(mJsonData);
if (jda.hasError()) {
const DataAccessError err = jda.error();
const QString errorMsg = tr("Error converting JSON data: %1").arg(err.errorMessage());
setResultAndState(errorMsg, JsonLoaded);
} else {
setQtData(qtData);
const QtObjectFormatter fmt;
setRhsTitleAndText(tr("Qt Data from JSON"), fmt.asString(qtData));
setResultAndState(result + tr("Success"), QtDisplayed);
}
}
示例12: load
void MyListModel::load(const QString& file_name)
{
// clear model
clear();
// clear not filtered data cache
m_data.clear();
{
JsonDataAccess jda;
m_data = jda.load(file_name).toList();
if (jda.hasError()) {
DataAccessError error = jda.error();
qDebug() << file_name << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
}
else {
qDebug() << file_name << "JSON data loaded OK!";
// when loaded, show all data (no filtering)
append(m_data);
}
}
}
示例13: onInvoked
void ApplicationUI::onInvoked(const bb::system::InvokeRequest &request)
{
qDebug() << "XXXX Received invoke=" << request.action();
if (request.action().compare(WAKEME_INVOKE_ACTION_STARTAPP) == 0) {
qDebug() << "XXXX Application Started started via Invoke with data: " << request.data().data() << endl;
JsonDataAccess jda;
QVariant parsedPayload = jda.loadFromBuffer(request.data());
if (!jda.hasError()) {
handleBeaconEvent(parsedPayload.toMap());
} else {
qWarning() << "XXXX ApplicationUI::onInvoked() - JSON parse error" << request.data() << endl;
}
} else {
qWarning() << "XXXX received invocation request we don't handle:" << request.action() << endl;
}
}
示例14: onReadyRead
void ApplicationUI::onReadyRead() {
QByteArray readData = _socket->readAll();
qDebug() << "XXXX Read: " << readData.constData() << endl;
JsonDataAccess jda;
QVariant parsedPayload = jda.loadFromBuffer(readData);
if (!jda.hasError()) {
QVariantMap payload = parsedPayload.toMap();
QString type = payload["TYPE"].toString();
if (type.compare("STATUS") == 0) {
QDateTime timeStamp = qvariant_cast<QDateTime>(payload["TIME_STAMP"]);
bool serverUp = qvariant_cast<bool>(payload["SERVER_UP"]);
bool scanning = qvariant_cast<bool>(payload["SCANNING"]);
bool btInitialised = qvariant_cast<bool>(payload["BT_INIT"]);
bool btRadioOn = qvariant_cast<bool>(payload["BT_RADIO_ON"]);
qDebug() << "XXXX timeStamp: " << timeStamp << endl;
qDebug() << "XXXX serverUp: " << serverUp << endl;
qDebug() << "XXXX scanning: " << scanning << endl;
qDebug() << "XXXX BT Initialised: " << btInitialised << endl;
qDebug() << "XXXX BT Radio On: " << btRadioOn << endl;
_scanning = scanning;
emit scanStateChanged(_scanning);
if (btRadioOn) {
emit message("Bluetooth Radio is ON");
} else {
emit message("Bluetooth Radio is OFF -- please enable it");
}
} else if ((type.compare("BEACON-ENTER-RANGE") == 0) || (type.compare("BEACON-EXIT-RANGE") == 0)) {
handleBeaconEvent(payload);
}
} else {
qWarning() << "XXXX ApplicationUI::onReadyRead() - JSON parse error" << readData.constData() << endl;
}
}
示例15: onRegistrationNewUser
void QBNetwork::onRegistrationNewUser() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
if (reply) {
const int available = reply->bytesAvailable();
if (available > 0) {
const QByteArray buffer(reply->readAll());
QString response = QString::fromUtf8(buffer);
JsonDataAccess jda;
QVariant qtData = jda.loadFromBuffer(response);
if (jda.hasError()) {
const DataAccessError err = jda.error();
emit error(
tr("Error converting JSON data: %1").arg(
err.errorMessage()));
} else {
QVariantMap userDetails = qtData.toMap()["user"].toMap();
if (userDetails.contains("id")) {
m_userId = userDetails["id"].toString();
}
}
if (m_token != NULL && m_userId != NULL) {
emit registered();
// requestLogin();
}
} else {
emit error("Wrong reply for register new user request");
}
reply->deleteLater();
} else {
emit error("Wrong reply for register new user request");
}
disconnectFromAll();
}