本文整理汇总了C++中qjson::Serializer类的典型用法代码示例。如果您正苦于以下问题:C++ Serializer类的具体用法?C++ Serializer怎么用?C++ Serializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Serializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveJSon
/*
{
"topFace" : "~/burp/faceZ/.png",
"bottomFace" : "~/burp/faceZ-/.png",
"leftFace" : "~/burp/faceY/.png",
"rightFace" : "~/burp/faceY-/.png",
"frontFace" : "~/burp/faceX/.png",
"backFace" : "~/burp/faceX-/.png",
"frameStart" : 1,
"frameStop" : 499,
"outputWidth" : 4094,
"antialiasing" : 1,
"aaPattern" : "grid",
"frames": [
{"cubemap": 1, "fov": 180, "pitch" : 0, "yaw" : 0, "roll" : 0, "zoom" : 0},
{"cubemap": 1, "fov": 180, "pitch" : 1, "yaw" : 2, "roll" : 3, "zoom" : 4},
{"cubemap": 1, "fov": 180, "pitch" : 2, "yaw" : 3, "roll" : 4, "zoom" : 1},
{"cubemap": 1, "fov": 180, "pitch" : 3, "yaw" : 4, "roll" : 1, "zoom" : 2},
{"cubemap": 1, "fov": 180, "pitch" : 4, "yaw" : 1, "roll" : 2, "zoom" : 3}
]
}
*/
void JSonIO::saveJSon(QString filePath){
QFile jsonFile(filePath);
if (!jsonFile.open(QIODevice::WriteOnly | QIODevice::Text)){
parserState = 1;
return;
}
QVariantMap root;
root.insert("outputFile", getOutputFile());
root.insert("topFace", getTopFace());
root.insert("bottomFace", getBottomFace());
root.insert("leftFace", getLeftFace());
root.insert("rightFace", getRightFace());
root.insert("frontFace", getFrontFace());
root.insert("backFace", getBackFace());
root.insert("frameStart", getFrameStart());
root.insert("frameStop", getFrameStop());
root.insert("outputWidth", getOutputWidth());
root.insert("antialiasing", getAntialiasing());
root.insert("aaPattern", getAaPattern());
root.insert("frames", frames);
QJson::Serializer serializer;
QByteArray json = serializer.serialize(root);
QTextStream out(&jsonFile);
out.setCodec("UTF-8");
out << json;
jsonFile.close();
qDebug() << "Saved to " << filePath;
}
示例2: closeIssue
void LYGithubManager::closeIssue(int issueNumber){
if(!isAuthenticated() || repository_.isEmpty() || closeIssueReply_)
return;
LYGithubProductBacklogStatusLog::statusLog()->appendStatusMessage("Starting closeIssue request");
QNetworkRequest request;
QString commentURL = QString("https://api.github.com/repos/%1/issues/%2").arg(repository_).arg(issueNumber);
request.setUrl(QUrl(commentURL));
QString userInfo = userName_+":"+password_;
QByteArray userData = userInfo.toLocal8Bit().toBase64();
QString headerData = "Basic " + userData;
request.setRawHeader("Authorization", headerData.toLocal8Bit());
QVariantMap jdata;
jdata["state"] = "closed";
QJson::Serializer jserializer;
QByteArray jsonData = jserializer.serialize(jdata);
QBuffer *buffer = new QBuffer;
buffer->setData(jsonData);
buffer->open(QIODevice::ReadOnly);
closeIssueReply_ = manager_->sendCustomRequest(request, "PATCH", buffer);
buffer->setParent(closeIssueReply_);
connect(closeIssueReply_, SIGNAL(readyRead()), this, SLOT(onCloseIssueReturned()));
}
示例3: RequestSharingEntry
void DriveManager::RequestSharingEntry (const QString& id,
const QString& key)
{
QString str = QString ("https://www.googleapis.com/drive/v2/files/%1/permissions?access_token=%2")
.arg (id, key);
QNetworkRequest request (str);
request.setHeader (QNetworkRequest::ContentTypeHeader, "application/json");
QVariantMap map;
map.insert ("kind", "drive#permission");
map.insert ("id", "anyoneWithLink");
map.insert ("role", "reader");
map.insert ("type", "anyone");
map.insert ("withLink", true);
QJson::Serializer serializer;
QNetworkReply *reply = Core::Instance ().GetProxy ()->
GetNetworkAccessManager ()->post (request, serializer.serialize (map));
Reply2Id_ [reply] = id;
connect (reply,
SIGNAL (finished ()),
this,
SLOT (handleRequestFileSharing ()));
}
示例4: updateFileContents
void LYGithubManager::updateFileContents(const QString &path, const QString &commitMessage, const QString &contents, const QString &sha){
if(!isAuthenticated() || repository_.isEmpty() || updateFileContentsReply_)
return;
LYGithubProductBacklogStatusLog::statusLog()->appendStatusMessage("Starting updateFileContents request");
QNetworkRequest request;
QString updateFileContentsURL = QString("https://api.github.com/repos/%1/contents/%2").arg(repository_).arg(path);
request.setUrl(QUrl(updateFileContentsURL));
QString userInfo = userName_+":"+password_;
QByteArray userData = userInfo.toLocal8Bit().toBase64();
QString headerData = "Basic " + userData;
request.setRawHeader("Authorization", headerData.toLocal8Bit());
QVariantMap jdata;
jdata["message"] = commitMessage;
QByteArray encodedContent = contents.toLocal8Bit().toBase64();
jdata["content"] = encodedContent;
jdata["sha"] = sha;
QJson::Serializer jserializer;
QByteArray jsonData = jserializer.serialize(jdata);
QBuffer *buffer = new QBuffer;
buffer->setData(jsonData);
buffer->open(QIODevice::ReadOnly);
updateFileContentsReply_ = manager_->sendCustomRequest(request, "PUT", buffer);
buffer->setParent(updateFileContentsReply_);
connect(updateFileContentsReply_, SIGNAL(readyRead()), this, SLOT(onUpdateFileContentsReturned()));
}
示例5: encode
QByteArray encode(const QVariant &claim, const QByteArray &key)
{
if(!QCA::isSupported("hmac(sha256)"))
return QByteArray();
QJson::Serializer serializer;
QVariantMap header;
header["typ"] = "JWT";
header["alg"] = "HS256";
QByteArray headerJson = serializer.serialize(header);
if(headerJson.isNull())
return QByteArray();
QByteArray claimJson = serializer.serialize(claim);
if(claimJson.isNull())
return QByteArray();
QByteArray headerPart = base64url(headerJson);
QByteArray claimPart = base64url(claimJson);
QByteArray sig = jws_sign(headerPart, claimPart, key);
return headerPart + '.' + claimPart + '.' + sig;
}
示例6: call
bool Peer::call(const QString &method, const QVariant ¶ms, const QVariant &id)
{
if (method.startsWith("rpc.")
|| (params.type() != QVariant::List
&& params.type() != QVariant::Map
&& !params.isNull())
|| (id.type() != QVariant::String
&& id.type() != QVariant::Int
&& id.type() != QVariant::ULongLong
&& id.type() != QVariant::LongLong
&& id.type() != QVariant::Double
&& !id.isNull()))
return false;
QVariantMap object;
object.insert("jsonrpc", "2.0");
object.insert("method", method);
if (!params.isNull())
object.insert("params", params);
object.insert("id", id);
QJson::Serializer serializer;
emit readyRequestMessage(serializer.serialize(object));
return true;
}
示例7: it
QByteArray
toJson( const QVariant &variant, bool* ok )
{
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
QVariant _variant = variant;
if ( variant.type() == QVariant::Hash )
{
// QJsonDocument cannot deal with QVariantHash, so convert.
const QVariantHash hash = variant.toHash();
QVariantMap map;
QHashIterator<QString, QVariant> it(hash);
while ( it.hasNext() )
{
it.next();
map.insert( it.key(), it.value() );
}
_variant = map;
}
QJsonDocument doc = QJsonDocument::fromVariant( _variant );
if ( ok != NULL )
{
*ok = !doc.isNull();
}
return doc.toJson( QJsonDocument::Compact );
#else
QJson::Serializer serializer;
return serializer.serialize( variant, ok );
#endif
}
示例8: getJson
QByteArray QuitSessionRequestJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("auth_token", m_sessionToken);
return serializer.serialize(obj);
}
示例9: put
int HueBridgeConnection::put(const QString &path, const QVariantMap ¶ms, QObject *sender, const QString &slot)
{
if (m_baseApiUrl.isEmpty()) {
qWarning() << "Not authenticated to bridge, cannot put" << path;
return -1;
}
QUrl url(m_baseApiUrl + path);
QNetworkRequest request;
request.setUrl(url);
#if QT_VERSION >= 0x050000
QJsonDocument jsonDoc = QJsonDocument::fromVariant(params);
QByteArray data = jsonDoc.toJson();
#else
QJson::Serializer serializer;
QByteArray data = serializer.serialize(params);
#endif
// qDebug() << "putting" << url << data;
QNetworkReply *reply = m_nam->put(request, data);
connect(reply, SIGNAL(finished()), this, SLOT(slotOpFinished()));
m_requestIdMap.insert(reply, m_requestCounter);
m_writeOperationList.append(reply);
CallbackObject co(sender, slot);
m_requestSenderMap.insert(m_requestCounter, co);
return m_requestCounter++;
}
示例10: recent
Cache::~Cache() {
QString error;
write_file(directory() + "/cache-info", &error, recent().join("\n").toAscii());
if (!error.isEmpty()) {
qFatal("Unable to save cache: %s", qPrintable(error));
}
foreach (QString name, recent()) {
if (!data().contains(name)) continue;
qDebug() << "Saving cached data:" << name;
QVariantMap map = data()[name].toMap();
QString error; bool ok; QJson::Serializer serializer;
write_file(directory() + '/' + name.replace('/', '-'), &error, serializer.serialize(map, &ok));
if (!error.isEmpty()) {
qWarning() << "Error while saving cache: " + error;;
continue;
}
if (!ok) {
error = INVALID_JSON + serializer.errorMessage();
qWarning() << "Error while saving cache: " + error;
continue;
}
}
}
示例11: respondOk
void respondOk(ZhttpRequest *req, const QVariant &data, const QByteArray &prefix = QByteArray(), const QByteArray &jsonpCallback = QByteArray())
{
HttpHeaders headers;
if(!jsonpCallback.isEmpty())
headers += HttpHeader("Content-Type", "application/javascript");
else
headers += HttpHeader("Content-Type", "text/plain");
QJson::Serializer serializer;
QByteArray body;
if(data.isValid())
body = serializer.serialize(data);
if(!prefix.isEmpty())
body.prepend(prefix);
if(!jsonpCallback.isEmpty())
{
QByteArray encBody = serializer.serialize(QString::fromUtf8(body));
body = "/**/" + jsonpCallback + '(' + encBody + ");\n";
}
else if(!body.isEmpty())
body += "\n"; // newline is required
respond(req, 200, "OK", headers, body);
}
示例12: getJson
QByteArray RestorePasswordRequestJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("email", m_usersContainer->at(0)->getEmail());
return serializer.serialize(obj);
}
示例13: post
void GrooveRequest::post()
{
QString cacheKey = generateCacheKey();
if (cacheKey.length()) {
qDebug() << Q_FUNC_INFO << "Possibly cached request";
QString cachePath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + "/libgroove/cache/api/" + cacheKey;
QFile cacheFile(cachePath);
if (cacheFile.open(QIODevice::ReadOnly)) {
qDebug() << Q_FUNC_INFO << "Definitely cached request";
QByteArray response = cacheFile.readAll();
processData(response);
return;
}
}
m_request.setHeader(m_request.ContentTypeHeader, "application/json");
QJson::Serializer serializer;
qDebug() << Q_FUNC_INFO << "Posting to: " << m_request.url();
qDebug() << Q_FUNC_INFO << serializer.serialize(buildRequest());
QNetworkReply *reply = m_client->networkManager()->post(m_request, serializer.serialize(buildRequest()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SIGNAL(error(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(finished()), SLOT(onFinished()));
}
示例14: getJson
QByteArray DefaultResponseJSON::getJson() const
{
QJson::Serializer serializer;
QVariantMap obj;
obj.insert("errno", m_errno);
return serializer.serialize(obj);
}
示例15: QString
/**
* To JSON
*/
QString *WorkModel::toJSON() {
QVariantMap variantMap = QJson::QObjectHelper::qobject2qvariant(this);
QJson::Serializer serializer;
QByteArray serializedArray = serializer.serialize(variantMap);
QString *jsonString = new QString(QString::fromUtf8(serializedArray));
return jsonString;
}