当前位置: 首页>>代码示例>>C++>>正文


C++ JsonDataAccess::loadFromBuffer方法代码示例

本文整理汇总了C++中JsonDataAccess::loadFromBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonDataAccess::loadFromBuffer方法的具体用法?C++ JsonDataAccess::loadFromBuffer怎么用?C++ JsonDataAccess::loadFromBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonDataAccess的用法示例。


在下文中一共展示了JsonDataAccess::loadFromBuffer方法的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;
}
开发者ID:Najibsaurus,项目名称:friendmap,代码行数:27,代码来源:LoginReply.cpp

示例2: onLineIsOpenFinished

void NetworkBus::onLineIsOpenFinished(QNetworkReply* reply){
	if(reply->error() != QNetworkReply::NoError){
		m_error = QString::fromUtf8("线路开通数据请求错误,请检查网络后重试!");
		onError();
		reply->deleteLater();
		return;
	}else{
		JsonDataAccess jda; // at are you
		const QVariant qtData = jda.loadFromBuffer(reply->readAll());
		// TODO if qtData has some error

		const QVariantMap map = qtData.toMap();
		const QString msg = map.values("msg").value(0).toString();
		const QString success = map.values("success").value(0).toString();
		if(success != "true" || msg != "ok"){
			m_error = QString::fromUtf8("线路开通返回失败,请检查网络后重试!");
			onError();
			return;
		}
		const QVariantList data = map["data"].toList();
		m_eid = data.at(0).toMap().value("eid").toString();
		m_isopen = data.at(0).toMap().value("isopen").toInt();
		qDebug() << "isOpen:" << m_isopen << "  eid:" << m_eid << "\n";
		reply->deleteLater();
		this->get_online_gps();
	}
}
开发者ID:codingkiller,项目名称:kumike2,代码行数:27,代码来源:network.cpp

示例3: 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();
}
开发者ID:QuickBlox,项目名称:quickblox-blackberry10-sdk,代码行数:28,代码来源:QBNetwork.cpp

示例4: 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;
}
开发者ID:yuguang,项目名称:friendmap,代码行数:30,代码来源:GetLocationsReply.cpp

示例5: onAlllineDataModelFinished

void NetworkBus::onAlllineDataModelFinished(QNetworkReply* reply){
	if(reply->error() != QNetworkReply::NoError){
		m_error = QString::fromUtf8("所有线路数据请求错误,请检查网络后重试!");
		onError();
		reply->deleteLater();
		return;
	}else{
		JsonDataAccess jda; // at are you
		const QVariant qtData = jda.loadFromBuffer(reply->readAll());
		// TODO if qtData has some error

		const QVariantMap map = qtData.toMap();
		const QString msg = map.values("msg").value(0).toString();
		const QString success = map.values("success").value(0).toString();
		if(success != "true" || msg != "ok"){
			m_error = QString::fromUtf8("所有线路数据返回不成功,请检查网络后重试!");
			onError();
			reply->deleteLater();
			return;
		}
		//

		const QVariantList data = map["data"].toList();
		if(data.isEmpty() || data.length() == 0){
			m_error = QString::fromUtf8("未查询到所有公交车线路数据!");
			onError();
			reply->deleteLater();
			return ;
		}
		QString result = "";
		m_alllineDataModel->clear();
		for(int i=0;i<data.length();i++){
			const QVariantMap iMap = data.at(i).toMap();
			busline *bus = new busline;
			bus->setBeginTime(iMap.value("begin_time").toString());
			bus->setEndTime(iMap.value("end_time").toString());
			bus->setId(iMap.value("id").toString());
			bus->setStartStation(iMap.value("start_station").toString());
			bus->setEndStation(iMap.value("end_station").toString());
			bus->setPrice(iMap.value("price").toString());
			bus->setLineName(iMap.value("line_name").toString());
			bus->setIsOpen(iMap.value("isopen").toInt());//1
			bus->setDir(iMap.value("dir").toInt());//0/1
			bus->setCityId(m_city_id);
			if(bus->getIsOpen() == 1)
			m_alllineDataModel->append(bus);
		}
		reply->deleteLater();
	}
	qDebug()<< "m_allline datamodel size:" << m_alllineDataModel->size();
	m_error = QString::fromUtf8("查询到所有公交车线路数据!");
	this->setProcess(false);
	emit processChanged();

	emit alllineDataModelChanged();
}
开发者ID:codingkiller,项目名称:kumike2,代码行数:56,代码来源:network.cpp

示例6: 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();
}
开发者ID:QuickBlox,项目名称:quickblox-blackberry10-sdk,代码行数:55,代码来源:QBNetwork.cpp

示例7: requestResponse

void VolumeRequest::requestResponse(QByteArray& result) {
	qDebug() << " DataRequest::requestResponse QString result=" << QString(result);
	
	JsonDataAccess jda;
	QVariant jsonVariant = jda.loadFromBuffer( QString(result));
	
	QVariantMap map = jsonVariant.toMap();
	QVariantList records = map.value("records").toList();
	
	emit success(mutateRecords(records));
}
开发者ID:adozenlines,项目名称:BES10-Cascades,代码行数:11,代码来源:VolumeRequest.cpp

示例8: onSublineInfFinished

//! [1]
void NetworkBus::onSublineInfFinished(QNetworkReply* reply){
	if(reply->error() != QNetworkReply::NoError){
		m_error = QString::fromUtf8("站点信息请求失败,请检查网络后重试!");
		onError();
		reply->deleteLater();
		return ;
	}else{
		JsonDataAccess jda; // at are you
		const QVariant qtData = jda.loadFromBuffer(reply->readAll());
		// TODO if qtData has some error

		const QVariantMap map = qtData.toMap();
		const QString msg = map.values("msg").value(0).toString();
		const QString success = map.values("success").value(0).toString();
		if(success != "true" || msg != "ok"){
			m_error = QString::fromUtf8("站点信息返回不成功,请稍后重试!");
			onError();
			reply->deleteLater();
			return;
		}
		const QVariantMap data = map["data"].toMap();
		const QVariantList stations = data["stations"].toList();
		if(stations.isEmpty() || stations.length() == 0){
			m_error = QString::fromUtf8("未查询到站点数据!");
			onError();
			reply->deleteLater();
			return ;
		}
		m_dataModel->clear();
		for(int i=0;i<stations.length();i++){
			const QVariantMap var = stations.at(i).toMap();
			station *sta = new station();
			sta->setCode(var["code"].toString());
			sta->setId(var["id"].toString());
			sta->setLat(var["lat"].toString());
			sta->setLng(var["lng"].toString());
		//	QString name = QString::number(i+1) ;
		//	name.append(var["name"].toString());
			sta->setIndex(QString::number(i+1));
		//	qDebug() << "name string : " << name ;
			sta->setName(var["name"].toString());
			if(m_dir == 0)
				startStation->append(sta);
			else endStation->append(sta);
		}
		m_dataModel->append(m_dir == 0 ? *startStation : *endStation);
	}
	qDebug() << "\nm_dataModel size :"<<m_dataModel->size() << "\n";
	emit dataModelChanged();
	emit buslineChanged();
	reply->deleteLater();
	this->get_lineisopen();
}
开发者ID:codingkiller,项目名称:kumike2,代码行数:54,代码来源:network.cpp

示例9: get_online_gps_finished

//! [1]
void NetworkBus::get_online_gps_finished(QNetworkReply* reply){
	if(reply->error() != QNetworkReply::NoError){
		m_error = QString::fromUtf8("GPS定位数据请求失败,请稍后重试!");
		onError();
		reply->deleteLater();
		return ;
	}else{
		JsonDataAccess jda; // at are you
		const QVariant qtData = jda.loadFromBuffer(reply->readAll());
		const QVariantMap map = qtData.toMap();

		const QVariantList records = map["records"].toList();
	//	const QVariantList stations = data["stations"].toList();
		if(records.isEmpty()){
			m_error = QString::fromUtf8("不在服务时间!");
			onError();
			reply->deleteLater();
			return ;
		}
		for(int i=0;i<m_dataModel->size()-1;i++){
			station* sta = m_dataModel->value(i);
			sta->setBusState(NULL);
		//	m_dataModel->value(i)->setBusState("");
			for(int j = 0 ; j < records.length();j++){
				const QStringList var = records.at(j).toStringList();
				const QString cur_station_state = var[19];
				const QString next_station = var[17];
				const QString cur_station = var[18];
				const QString subline_ids = var[20];
				if(subline_id() != subline_ids) continue;
			//	float leftPadding = 0;
				if(cur_station == m_dataModel->value(i)->name() && next_station == m_dataModel->value(i+1)->name()){
					if(cur_station_state != "2"){//显示在站点
					//	m_dataModel->value(i)->setBusState("cur_station");
						sta->setBusState("cur_station");
					}
					else{//显示正中间
					//	m_dataModel->value(i)->setBusState("middle");
						sta->setBusState("middle");
					}
				}
			}
			m_dataModel->replace(i,sta);
		}
	}
	setProcess(false);
	emit processChanged();
	emit busstateChanged();
	reply->deleteLater();
}
开发者ID:codingkiller,项目名称:kumike2,代码行数:51,代码来源:network.cpp

示例10: onFinished

void NetworkManager::onFinished(QNetworkReply* reply) {
    using namespace bb::data;
    bool disconnected = disconnect(&m_netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
    Q_ASSERT(disconnected);
    if (reply->error() == QNetworkReply::NoError) {
        JsonDataAccess json;
        QString contentString = reply->readAll();
        QVariantMap content = json.loadFromBuffer(contentString).toMap();
        bool ok;
        int replyCode = content["id"].toInt(&ok);
        if (!ok) replyCode = -1;
        emit confirmationCode(replyCode);
    }
    reply->deleteLater();
}
开发者ID:dielsonsales,项目名称:emailconfirmation,代码行数:15,代码来源:NetworkManager.cpp

示例11: 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();
}
开发者ID:QuickBlox,项目名称:quickblox-blackberry10-sdk,代码行数:48,代码来源:QBNetwork.cpp

示例12: onArtistReply

void RocknRoll::onArtistReply(QNetworkReply* reply)
{
	QString response;
	bool success = false;
	if(reply)
	{
		if(reply->error() == QNetworkReply::NoError)
		{
			int available = reply->bytesAvailable();
			QString jString = reply->readAll();
			qDebug() << "jString ================= " << jString;
			JsonDataAccess jda;
			//QVariantList list = jda.loadFromBuffer(jString)->toValue<QVariantList>();
			QVariantList list = jda.loadFromBuffer(jString).value<QVariantList>();
			qDebug() <<"lisssssssssssssssssssssssssssssssst " << list;
//			if (available > 0)
//			{
//				int bufSize = sizeof(char) * available + sizeof(char);
//				QByteArray buffer(bufSize, 0);
//				int read = reply->read(buffer.data(), available);
//				response = QString(buffer);
//				QJsonDocument jdoc = response.toJson();
//				qDebug() << "****** " << response << " ******" << endl;
//				JsonDataAccess jda;
//				QVariant list = jda.load("/bb10_client/dummy.json");
//				QVariant jdoc = jda.loadFromBuffer(response);
//				QList<QVariant> list = jdoc.toList();
//				qDebug() << "null jdoc: " << jdoc.isNull() << endl;
//				qDebug() << "empty jdoc: " << jdoc.isEmpty() << endl;
//				success = true;
//			}
		}
		else
		{
			response = QString("Error: ") + reply->errorString() + QString(" status: ") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
			qDebug() << response;
		}
		reply->deleteLater();
	}
	if (response.trimmed().isEmpty())
	{
		response = QString("Request failed. Check connection");
		qDebug() << response;
	}
	emit complete(response, success);

}
开发者ID:sanjayasl,项目名称:RocknRoll,代码行数:47,代码来源:RocknRoll.cpp

示例13: childCardDone

void SocialInvocation::childCardDone(const bb::system::CardDoneMessage &doneMessage)
{
	SystemToast* toast = new SystemToast(this);
	if (doneMessage.dataType().compare("application/json") == 0)
	{
		// The data type from the venue search card is application/json
		// so we need to convert the json data to a map here. This will match
		// the json format from the Foursquare docs at http://developer.foursquare.com
		JsonDataAccess jda;
		const QVariantMap venueMap = jda.loadFromBuffer(doneMessage.data()).toMap();
		toast->setBody(QString("User Picked: ") + venueMap.value("name","").toString());
	}
	else
	{
		toast->setBody(doneMessage.data());
	}
	toast->show();
}
开发者ID:AnujAroshA,项目名称:Cascades-Samples,代码行数:18,代码来源:SocialInvocation.cpp

示例14: onNetworkManagerReply

void QBNetwork::onNetworkManagerReply(QNetworkReply *reply) {
	setLoadAction(false);
	if (reply->error() == QNetworkReply::NoError) {
//		qDebug() << "success reply";
	} else {
		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);

			//TODO simplest way for change default server responses
			if (response.contains("login") && response.contains("has already been taken")) {
				emit error ("Login has already been taken");
			}
			else if (response.contains("Unauthorized")) {
				emit error ("login or password is incorrect");
			}
			else {
//			if (jda.hasError()) {
				emit error("Error response from QB " + response);
			}
//			} else {
//				QString result = "Error response from QB";
//				QVariantMap errorsMap =  qtData.toMap()["errors"].toMap();
//				foreach(const QVariant& errorKey, errorsMap.keys())
//				{
//					result += "\n" + errorKey.toString() + ":";
//					foreach(const QVariant& errorValue, errorsMap[errorKey.toString()].toList())
//					{
//						result += errorValue.toString() + " ";
//					}
//				}
//				emit error(result);
//			}
		}
		else {
			//haven't QB error response
			handleError(reply);
		}
	}
}
开发者ID:QuickBlox,项目名称:quickblox-blackberry10-sdk,代码行数:44,代码来源:QBNetwork.cpp

示例15: parseResponse

//! [4]
void App::parseResponse(const QString &response)
{
    m_model->clear();

    if (response.trimmed().isEmpty())
        return;

    // Parse the json response with JsonDataAccess
    JsonDataAccess dataAccess;
    const QVariantMap variant = dataAccess.loadFromBuffer(response).toMap();

    // The qvariant is a map of searches which is extracted as a list
    const QVariantList feed = variant["response"].toMap()["docs"].toList();

    // For each object in the array, push the variantmap in its raw form
    // into the ListView
    foreach (const QVariant &artifact, feed) {
        m_model->insert(artifact.toMap());
    }
开发者ID:13natty,项目名称:Cascades-Samples,代码行数:20,代码来源:app.cpp


注:本文中的JsonDataAccess::loadFromBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。