本文整理汇总了C++中qjson::Parser::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ Parser::parse方法的具体用法?C++ Parser::parse怎么用?C++ Parser::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qjson::Parser
的用法示例。
在下文中一共展示了Parser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FetchWikipediaImages
void ArtistBiography::FetchWikipediaImages(int id, const QString& wikipedia_url,
CountdownLatch* latch) {
latch->Wait();
qLog(Debug) << wikipedia_url;
QRegExp regex("([a-z]+)\\.wikipedia\\.org/wiki/(.*)");
if (regex.indexIn(wikipedia_url) == -1) {
emit Finished(id);
return;
}
QString wiki_title = QUrl::fromPercentEncoding(regex.cap(2).toUtf8());
QString language = regex.cap(1);
QUrl url(QString(kWikipediaImageListUrl).arg(language));
url.addQueryItem("titles", wiki_title);
qLog(Debug) << "Wikipedia images:" << url;
QNetworkRequest request(url);
QNetworkReply* reply = network_->get(request);
NewClosure(reply, SIGNAL(finished()), [this, id, reply, language, latch]() {
reply->deleteLater();
QJson::Parser parser;
QVariantMap response = parser.parse(reply).toMap();
QStringList image_titles = ExtractImageTitles(response);
for (const QString& image_title : image_titles) {
latch->Wait();
QUrl url(QString(kWikipediaImageInfoUrl).arg(language));
url.addQueryItem("titles", image_title);
qLog(Debug) << "Image info:" << url;
QNetworkRequest request(url);
QNetworkReply* reply = network_->get(request);
NewClosure(reply, SIGNAL(finished()), [this, id, reply, latch]() {
reply->deleteLater();
QJson::Parser parser;
QVariantMap json = parser.parse(reply).toMap();
QUrl url = ExtractImageUrl(json);
qLog(Debug) << "Found wikipedia image url:" << url;
if (!url.isEmpty()) {
emit ImageReady(id, url);
}
latch->CountDown();
});
}
latch->CountDown();
});
}
示例2: decode
QVariant decode(const QByteArray &token, const QByteArray &key)
{
if(!QCA::isSupported("hmac(sha256)"))
return QVariant();
int at = token.indexOf('.');
if(at == -1)
return QVariant();
QByteArray headerPart = token.mid(0, at);
++at;
int start = at;
at = token.indexOf('.', start);
if(at == -1)
return QVariant();
QByteArray claimPart = token.mid(start, at - start);
QByteArray sig = token.mid(at + 1);
bool ok;
QJson::Parser parser;
QByteArray headerJson = unbase64url(headerPart);
if(headerJson.isEmpty())
return QVariant();
QVariant headerObj = parser.parse(headerJson, &ok);
if(!ok || headerObj.type() != QVariant::Map)
return QVariant();
QVariantMap header = headerObj.toMap();
if(header.value("typ").toString() != "JWT" || header.value("alg").toString() != "HS256")
return QVariant();
QByteArray claimJson = unbase64url(claimPart);
if(claimJson.isEmpty())
return QVariant();
QVariant claim = parser.parse(claimJson, &ok);
if(!ok)
return QVariant();
if(jws_sign(headerPart, claimPart, key) != sig)
return QVariant();
return claim;
}
示例3: 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();
}
示例4: connected
void
GrooveClient::Private::processSessionToken ()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *> (sender ());
if (GROOVE_VERIFY (reply, "called without a QNetworkReply as sender"))
return;
bool ok;
QJson::Parser parser;
QByteArray sessionTokenReply = reply->readAll ();
QVariantMap result = parser.parse (sessionTokenReply, &ok).toMap ();
if (!ok)
LDEBUG << "Session token request failed:" << sessionTokenReply;
GROOVE_VERIFY_OR_DIE (ok, "couldn't parse reply to session token request");
GROOVE_VERIFY_OR_DIE (result["message"].toString ().isEmpty (), qPrintable (result["message"].toString ()));
m_sessionToken = result["result"].toString ();
LDEBUG << "Got session token: " << m_sessionToken;
if (!m_sessionToken.length ())
{
LDEBUG << "Session token empty:";
LDEBUG << sessionTokenReply;
LDEBUG << reply->errorString ();
}
emit connected ();
}
示例5: 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;
}
示例6: parseJson
bool FilterPolygonRequestJSON::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"));
FShapePolygon * shape = new FShapePolygon();
QVariantList polygon = result["polygon"].toList();
for (int i = 0; i < polygon.size(); i++)
{
QVariantMap p = polygon.at(i).toMap();
int number = p["number"].toInt(&ok);
if (!ok) return false;
double lat = p["latitude"].toDouble(&ok);
if (!ok) return false;
double lon = p["longitude"].toDouble(&ok);
if (!ok) return false;
shape->addPoint(number, lat, lon);
}
setShape(QSharedPointer<FShape>(shape));
m_sessionsContainer->push_back(QSharedPointer<Session>(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL))));
return true;
}
示例7: parseReplyDataVariant
QVariant ContentItemInterfacePrivate::parseReplyDataVariant(const QByteArray &replyData, bool *ok)
{
QVariant parsed;
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QJson::Parser jsonParser;
parsed = jsonParser.parse(replyData, ok);
if (!*ok) {
qWarning() << Q_FUNC_INFO << "Error parsing JSON file:" << jsonParser.errorString()
<< "at" << jsonParser.errorLine();
}
#else
QJsonParseError jsonError;
QJsonDocument jsonDocument = QJsonDocument::fromJson(replyData, &jsonError);
*ok = !jsonDocument.isEmpty();
if (!*ok) {
qWarning() << Q_FUNC_INFO << "Error parsing JSON file:" << jsonError.errorString()
<< "at" << jsonError.offset;
}
parsed = jsonDocument.toVariant();
#endif
if (!*ok) {
parsed.clear();
}
return parsed;
}
示例8: WorkModel
/**
* From JSON
*/
WorkModel * WorkModel::fromJSON(QString *jsonString) {
QJson::Parser parser;
QVariant variant = parser.parse(jsonString->toUtf8());
WorkModel *workModel = new WorkModel();
QJson::QObjectHelper::qvariant2qobject(variant.toMap(), workModel);
return workModel;
}
示例9: 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;
}
示例10: 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");
QSharedPointer<Session> session(new JsonSession(auth_token, QDateTime::currentDateTime(), QSharedPointer<common::User>(NULL)));
QSharedPointer<Channel> channel(new JsonChannel(channel_name, "unknown"));
QSharedPointer<DataMark> tag(new JsonDataMark(altitude, latitude, longitude, title, description, link, time));
//tag->setChannel(channel);
//tag->setSession(session);
m_channelsContainer->push_back(channel);
m_sessionsContainer->push_back(session);
m_tagsContainer->push_back(tag);
return true;
}
示例11: 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();
}
}
}
示例12: 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();
}
示例13: 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;
}
示例14: collectItems
void LinTORManager::collectItems()
{
// Marshall the current item:
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(torItemReply->readAll(), &ok).toMap();
torItemReply->deleteLater();
torItemReply = 0;
if (!ok)
{
qWarning() << "Failed to parse The Old Reader item contents";
return;
}
// Try to pull the usable bits out of the item contents:
QList<QVariant> itemsVariants = result["items"].toList();
QList<QVariant>::const_iterator index = itemsVariants.constBegin();
QList<QVariant>::const_iterator end = itemsVariants.constEnd();
while (index != end)
{
QVariantMap itemMap = (*index).toMap();
LinTORItem item;
item.setTitle(itemMap["title"].toString());
QList<QVariant> canonicalList = itemMap["canonical"].toList();
// For now, just pull the first item out of the list:
if (!canonicalList.isEmpty())
{
QVariantMap canonicalMap = canonicalList.first().toMap();
item.setSourceUrl(canonicalMap["href"].toString());
}
QList<QVariant> enclosureList = itemMap["enclosure"].toList();
// For now, just pull the first item out of the list:
if (!enclosureList.isEmpty())
{
QVariantMap enclosureMap = enclosureList.first().toMap();
item.setEnclosureUrl(enclosureMap["href"].toString());
item.setEnclosureType(enclosureMap["type"].toString());
}
QVariantMap summaryMap = itemMap["summary"].toMap();
item.setSummary(summaryMap["content"].toString());
torItems[itemMap["id"].toString()] = item;
++index;
}
emit itemsReady();
}
示例15: 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();
}
}