本文整理汇总了C++中qjson::Parser类的典型用法代码示例。如果您正苦于以下问题:C++ Parser类的具体用法?C++ Parser怎么用?C++ Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnObserve
virtual void OnObserve(const char* aTopic, const PRUnichar* aData) {
// LOGT("aTopic: %s, data: %s", aTopic, NS_ConvertUTF16toUTF8(aData).get());
QString data((QChar*)aData);
if (!data.startsWith('{') && !data.startsWith('[') && !data.startsWith('"')) {
QVariant vdata = QVariant::fromValue(data);
Q_EMIT q->recvObserve(aTopic, vdata);
return;
}
bool ok = true;
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QJson::Parser parser;
QVariant vdata = parser.parse(data.toUtf8(), &ok);
#else
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8(), &error);
ok = error.error == QJsonParseError::NoError;
QVariant vdata = doc.toVariant();
#endif
if (ok) {
// LOGT("mesg:%s, data:%s", aTopic, data.toUtf8().data());
Q_EMIT q->recvObserve(aTopic, vdata);
} else {
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
LOGT("parse: s:'%s', err:%s, errLine:%i", data.toUtf8().data(), parser.errorString().toUtf8().data(), parser.errorLine());
#else
LOGT("parse: s:'%s', err:%s, errLine:%i", data.toUtf8().data(), error.errorString().toUtf8().data(), error.offset);
#endif
}
}
示例2: qDebug
const SipInfo
SipInfo::fromJson( QString json )
{
SipInfo info;
QJson::Parser parser;
bool ok;
QVariant v = parser.parse( json.toAscii(), &ok );
if ( !ok || v.type() != QVariant::Map )
{
qDebug() << Q_FUNC_INFO << "Invalid JSON: " << json;
return info;
}
QVariantMap m = v.toMap();
info.setVisible( m["visible"].toBool() );
if( m["visible"].toBool() )
{
QHostInfo hostInfo;
hostInfo.setHostName( m["host"].toString() );
info.setHost( hostInfo );
info.setPort( m["port"].toInt() );
info.setUniqname( m["uniqname"].toString() );
info.setKey( m["key"].toString() );
}
return info;
}
示例3: downLoadDataFinished
void MusicKWBackgroundThread::downLoadDataFinished(const QByteArray &bytes)
{
QJson::Parser parser;
bool ok;
if(bytes != "NO_PIC")
{
QVariant data = parser.parse(bytes, &ok);
if(ok)
{
QVariantMap dataMap = data.toMap();
QVariantList datas = dataMap["array"].toList();
foreach(const QVariant &value, datas)
{
dataMap = value.toMap();
if(m_counter < 5 && !dataMap.isEmpty())
{
QString url = dataMap.values().first().toString();
M_LOGGER_ERROR(url);
MusicDataDownloadThread *download = new MusicDataDownloadThread(url, QString("%1%2%3%4").arg(BACKGROUND_DIR_FULL)
.arg(m_savePath).arg(m_counter++).arg(SKN_FILE),
MusicDownLoadThreadAbstract::DownloadBigBG, this);
connect(download, SIGNAL(downLoadDataChanged(QString)), SLOT(downLoadFinished()));
download->startToDownload();
}
}
}
示例4: ReadJSONFromFile
/*
Reads a JSON file and returns the parsed version of it as a QVariantMap
*/
QVariantMap ReadJSONFromFile(QString filename) {
QFile file(filename);
if (!file.exists()) {
QString s = "File does not exist: ";
s.append(filename);
throw JSONOpenError(s.toStdString());
}
QByteArray rawstring;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString s = "Failure to open: ";
s.append(filename);
throw JSONOpenError(s.toStdString());
}
while (!file.atEnd()) {
rawstring.append(file.readLine());
}
QJson::Parser parser;
bool ok;
QVariantMap results = parser.parse(rawstring, &ok).toMap();
if (!ok) {
QString s = "Failure to parse: ";
s.append(filename);
throw JSONParseError(s.toStdString());
}
return results;
}
示例5: handleFinished
void QgsAmsLegendFetcher::handleFinished()
{
// Parse result
QJson::Parser parser;
bool ok = false;
QVariantMap queryResults = parser.parse( mQueryReply, &ok ).toMap();
if ( !ok )
{
emit error( QString( "Parsing error at line %1: %2" ).arg( parser.errorLine() ).arg( parser.errorString() ) );
}
QgsDataSourceUri dataSource( mProvider->dataSourceUri() );
QList< QPair<QString, QImage> > legendEntries;
foreach ( const QVariant& result, queryResults["layers"].toList() )
{
QVariantMap queryResultMap = result.toMap();
QString layerId = queryResultMap["layerId"].toString();
if ( layerId != dataSource.param( "layer" ) && !mProvider->subLayers().contains( layerId ) )
{
continue;
}
QVariantList legendSymbols = queryResultMap["legend"].toList();
foreach ( const QVariant& legendEntry, legendSymbols )
{
QVariantMap legendEntryMap = legendEntry.toMap();
QString label = legendEntryMap["label"].toString();
if ( label.isEmpty() && legendSymbols.size() == 1 )
label = queryResultMap["layerName"].toString();
QByteArray imageData = QByteArray::fromBase64( legendEntryMap["imageData"].toByteArray() );
legendEntries.append( qMakePair( label, QImage::fromData( imageData ) ) );
}
}
示例6: receiveAuthToken
void LinTORManager::receiveAuthToken()
{
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(authReply->readAll(), &ok).toMap();
authReply->deleteLater();
authReply = 0;
if (!ok)
{
qWarning() << "Failed to parse The Old Reader authorization data";
emit loginFailed();
return;
}
authToken = result["Auth"].toString();
authHeaderString = "GoogleLogin auth=";
authHeaderString += authToken;
qDebug() << "Authentication: " << authHeaderString;
// Initialize the display:
getFolders();
// getUnread();
// getSubscriptions();
}
示例7: foreach
DigitallyImportedClient::ChannelList
DigitallyImportedClient::ParseChannelList(QNetworkReply* reply) const {
ChannelList ret;
QJson::Parser parser;
QVariantMap data = parser.parse(reply).toMap();
if (!data.contains("channel_filters"))
return ret;
QVariantList filters = data["channel_filters"].toList();
foreach (const QVariant& filter, filters) {
// Find the filter called "All"
QVariantMap filter_map = filter.toMap();
if (filter_map.value("name", QString()).toString() != "All")
continue;
// Add all its stations to the result
QVariantList channels = filter_map.value("channels", QVariantList()).toList();
foreach (const QVariant& channel_var, channels) {
QVariantMap channel_map = channel_var.toMap();
Channel channel;
channel.art_url_ = QUrl(channel_map.value("asset_url").toString());
channel.description_ = channel_map.value("description").toString();
channel.director_ = channel_map.value("channel_director").toString();
channel.key_ = channel_map.value("key").toString();
channel.name_ = channel_map.value("name").toString();
ret << channel;
}
示例8: parseJson
bool GetBlobResponseJSON::parseJson(const QByteArray &data)
{
clearContainers();
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse (data, &ok).toMap ();
if (!ok)
return false;
/*result["errno"].toInt(&ok);
if (!ok) return false;*/
int errno = result["errno"].toInt();
QString blob = result["blob"].toString ();
/*if (blob.isEmpty())
{
DEBUG() << "Some of the string fields are empty." << data;
return false;
}*/
m_errno = errno;
m_blob = blob;
return true;
}
示例9: parseFolderDo
void QgsArcGisRestCatalogProvider::parseFolderDo()
{
QNetworkReply* reply = qobject_cast<QNetworkReply*>( QObject::sender() );
reply->deleteLater();
QString path = reply->property( "path" ).toString();
QStringList catTitles = reply->property( "catTitles" ).toStringList();
if ( reply->error() == QNetworkReply::NoError )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QJson::Parser parser;
QVariantMap folderData = parser.parse( reply->readAll() ).toMap();
#else
QVariantMap folderData = QJsonDocument::fromJson( reply->readAll() ).object().toVariantMap();
#endif
QString catName = QFileInfo( path ).baseName();
if ( !catName.isEmpty() )
{
catTitles.append( catName );
}
foreach ( const QVariant& folderName, folderData["folders"].toList() )
{
parseFolder( path + "/" + folderName.toString(), catTitles );
}
foreach ( const QVariant& serviceData, folderData["services"].toList() )
{
parseService( QString( "/" ) + serviceData.toMap()["name"].toString(), catTitles );
}
}
示例10: downLoadFinished
void MusicIdentifySongsThread::downLoadFinished()
{
m_songIdentifys.clear();
if(m_reply && m_reply->error() == QNetworkReply::NoError)
{
QJson::Parser parser;
bool ok;
QVariant data = parser.parse(m_reply->readAll(), &ok);
if(ok)
{
QVariantMap value = data.toMap();
if(value.contains("metadata"))
{
value = value["metadata"].toMap();
QVariantList list = value["music"].toList();
foreach(const QVariant &var, list)
{
value = var.toMap();
MusicSongIdentify song;
song.m_songName = value["title"].toString();
foreach(const QVariant &artists, value["artists"].toList())
{
value = artists.toMap();
song.m_singerName = value["name"].toString();
break;
}
m_songIdentifys << song;
break;
}
}
示例11: parseResponseAddPhoto
void DBTalker::parseResponseAddPhoto(const QByteArray& data)
{
bool success = false;
QJson::Parser parser;
bool ok;
QVariant result = parser.parse(data, &ok);
QVariantMap rmap = result.toMap();
QList<QString> keys = rmap.uniqueKeys();
for(int i=0;i<rmap.size();i++)
{
if(keys[i] == "bytes")
{
success = true;
break;
}
}
emit signalBusy(false);
if(!success)
{
emit signalAddPhotoFailed(i18n("Failed to upload photo"));
}
else
{
emit signalAddPhotoSucceeded();
}
}
示例12: parseJson
bool WriteTagRequestJSON::parseJson(const QByteArray &data)
{
clearContainers();
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;
QString auth_token = result["auth_token"].toString();
QString channel_name = result["channel"].toString();
QString title = result["title"].toString();
QString link = result["link"].toString();
QString description = result["description"].toString();
double altitude = result["altitude"].toDouble(&ok);
if (!ok) return false;
double longitude = result["longitude"].toDouble(&ok);
if (!ok) return false;
double latitude = result["latitude"].toDouble(&ok);
if (!ok) return false;
QDateTime time = QDateTime::fromString(result["time"].toString(), "dd MM yyyy HH:mm:ss.zzz");
Session session(auth_token, QDateTime::currentDateTime(), common::BasicUser());
Channel channel(channel_name, "unknown");
Tag tag(altitude, latitude, longitude, title, description, link, time);
tag.setChannel(channel);
//tag.setSession(session);
m_channels.push_back(channel);
m_token = auth_token;
m_tags.push_back(tag);
return true;
}
示例13: parseJson
bool FilterRectangleRequestJSON::parseJson(const QByteArray&data)
{
clearContainers();
FilterRequestJSON::parseJson(data);
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(data, &ok).toMap();
if (!ok) return false;
QString auth_token = result["auth_token"].toString();
setTimeFrom(QDateTime::fromString(result["time_from"].toString(), "dd MM yyyy HH:mm:ss.zzz"));
setTimeTo(QDateTime::fromString(result["time_to"].toString(), "dd MM yyyy HH:mm:ss.zzz"));
double lat1, lat2, lon1, lon2;
QVariantMap latData = result["latitude_shift"].toMap();
lat1 = latData["latitude1"].toDouble(&ok);
if (!ok) return false;
lat2 = latData["latitude2"].toDouble(&ok);
if (!ok) return false;
QVariantMap lonData = result["longitude_shift"].toMap();
lon1 = lonData["longitude1"].toDouble(&ok);
if (!ok) return false;
lon2 = lonData["longitude2"].toDouble(&ok);
if (!ok) return false;
syslog(LOG_INFO, "rect %f ,%f ,%f ,%f ", lat1, lat2, lon2, lon2);
FShapeRectangle * shape = new FShapeRectangle(lat1, lon1, lat2, lon2);
setShape(QSharedPointer<FShape>(shape));
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));
return true;
}
示例14: ListFilesFinished
void SkydriveService::ListFilesFinished(QNetworkReply* reply) {
reply->deleteLater();
QJson::Parser parser;
QVariantMap response = parser.parse(reply).toMap();
QVariantList files = response["data"].toList();
for (const QVariant& f : files) {
QVariantMap file = f.toMap();
if (file["type"].toString() == "folder") {
ListFiles(file["id"].toString());
} else {
QString mime_type = GuessMimeTypeForFile(file["name"].toString());
QUrl url;
url.setScheme("skydrive");
url.setPath(file["id"].toString());
Song song;
song.set_url(url);
song.set_ctime(file["created_time"].toDateTime().toTime_t());
song.set_mtime(file["updated_time"].toDateTime().toTime_t());
song.set_comment(file["description"].toString());
song.set_filesize(file["size"].toInt());
song.set_title(file["name"].toString());
QUrl download_url = file["source"].toUrl();
// HTTPS appears to be broken somehow between Qt & Skydrive downloads.
// Fortunately, just changing the scheme to HTTP works.
download_url.setScheme("http");
MaybeAddFileToDatabase(song, mime_type, download_url, QString::null);
}
}
}
示例15: errorOccured
void PlacesDataManager::
replyFinished(QNetworkReply * reply) const
{
QApplication::restoreOverrideCursor();
if( existsReplyError(reply) ) return;
QString strUrl = reply->url().toString();
QString data = reply->readAll();
//qDebug() << Q_FUNC_INFO << "\n" << reply->operation() << strUrl << "\n" << data;
QObject * origObject = reply->request().originatingObject();
//it's ok, just simple usage of QNetworkAccessManager, without DataManagerHelper
if( ! origObject ) {
//qDebug() << "empty originating Object...";
//qDebug() << "try simple work with result";
//qDebug() << data;
QJson::Parser parser;
bool ok;
// json is a QString containing the data to convert
QVariant result = parser.parse (data.toLatin1(), &ok);
if(!ok)
{
emit errorOccured(QString("Cannot convert to QJson object: %1").arg(data));
return;
}
int code = result.toMap()["Status"].toMap()["code"].toInt();
if(code != 200 && code != 0)
{
emit errorOccured(QString("Code of request is: %1").arg(code));
return;
}
QVariantList placeMarks = result.toMap()["Placemark"].toList();
if (!placeMarks.empty())
{
double east = placeMarks[0].toMap()["Point"].toMap()["coordinates"].toList()[0].toDouble();
double north = placeMarks[0].toMap()["Point"].toMap()["coordinates"].toList()[1].toDouble();
QString str = QString::number(north)+","+QString::number(east);
emit findCoordinatesByAddress(str);
}
return;
}
DataManagerHelper * helper = qobject_cast<DataManagerHelper*>(origObject);
if( ! helper ) {
//qDebug() << "empty helper Object...";
return;
}
//qDebug() << "Helper object present." ;
helper->evalData(data);
helper->deleteLater();
}