void Serializer::serialize(QString file, Configuration* config)
	{
        Lemniscate* lemniscate = config->getLemniscate();
        QJsonObject lemniscateObj;
        lemniscate->write(lemniscateObj);
		QJsonObject jsonObject;
        jsonObject[KEY_LEMNISCATE] = lemniscateObj;

		QJsonObject panelObj;
		config->getPanel()->write(panelObj);
		jsonObject[KEY_PANEL] = panelObj;

		QJsonDocument jsonDocument(jsonObject);
		QFile jsonFile(file);
		if (!jsonFile.exists())
		{
			jsonFile.setFileName(file + ".json");
		}
		if (!jsonFile.open(QIODevice::WriteOnly))
		{
			throw ConfigSerializerException("error opening file for writing");
		}
		if (-1 == jsonFile.write(jsonDocument.toJson()))
		{
			throw ConfigSerializerException("error writing to file");
		}
	}
Beispiel #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QFile saveFile("/Users/Ulle/temp/test.txt");

    if (!saveFile.open(QIODevice::WriteOnly))
    {
        qWarning("Couldn't open save file.");
    }

    QJsonObject jsonObject;

    QJsonArray jsonArray;
    for (int i = 0; i < 3; i++)
    {
        jsonArray.append(i+0.5);
        /*QJsonObject jsonObject;
        jsonObject["intTest"] = i;
        jsonArray.append(jsonObject);*/
    }

    jsonObject["arrayTest"] = jsonArray;

    for (int i = 0; i < 3; i++)
    {
        qDebug() << jsonObject["arrayTest"].toArray()[i].toDouble();
    }


    QJsonDocument jsonDocument(jsonObject);
    saveFile.write(jsonDocument.toJson());
}
Beispiel #3
0
void Client::writeNewUser()
{
    QJsonDocument jsonDocument(newUser);
    userSent = jsonDocument.toJson(QJsonDocument::Compact);
    QByteArray byteArrayJson(userSent.toStdString().c_str());
    socket->write(byteArrayJson);
    socket->flush();
    elapsedTime.start();
}
Beispiel #4
0
qint64 NodeList::sendStats(const QJsonObject& statsObject, const HifiSockAddr& destination) {
    auto statsPacketList = NLPacketList::create(PacketType::NodeJsonStats, QByteArray(), true, true);

    QJsonDocument jsonDocument(statsObject);
    statsPacketList->write(jsonDocument.toBinaryData());

    sendPacketList(std::move(statsPacketList), destination);

    // enumerate the resulting strings, breaking them into MTU sized packets
    return 0;
}
void WebSocketManager::retrieveAuthToken()
{
    QByteArray hashTemplate(m_settings->value("login", kLogin).toByteArray());
    hashTemplate.append(":");
    hashTemplate.append(m_settings->value("password", kPassword).toString());

    QByteArray hash = QCryptographicHash::hash(hashTemplate, QCryptographicHash::Md5).toHex();
    QJsonObject jsonObject;
    QJsonObject jsonData;
    jsonData["credentials"] = hash.data();
    jsonData["realm"] = m_settings->value("realm", kRealm).toString();
    jsonObject["data"] = jsonData;
    QJsonDocument jsonDocument(jsonObject);
    QByteArray json = jsonDocument.toJson();

    QNetworkRequest req;
    req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    req.setUrl(QUrl(m_settings->value("auth_url", kAuthUrl).toString()));
    QNetworkReply *reply = m_nam->put(req, json);
    connect(reply, &QNetworkReply::finished,
            this, &WebSocketManager::retrieveAuthTokenFinished);
}
Beispiel #6
0
void PointsLoader::serializePoints(const PointsLoader::MapPointList& points, std::string& outString)
{
    rapidjson::MemoryPoolAllocator<> allocator;
    rapidjson::CrtAllocator allocatorCrt;
    
    rapidjson::Document jsonDocument(&allocator);
    jsonDocument.SetArray();
    for(const auto& point : points)
    {
        rapidjson::Value element;
        element.SetObject();
        
        rapidjson::Value position;
        position.SetArray();
        position.Reserve(2, allocator);
        position.PushBack(point.point.x, allocator);
        position.PushBack(point.point.y, allocator);
        
        rapidjson::Value name;
        name.SetString(point.name.c_str(), point.name.size());
        
        rapidjson::Value desc;
        desc.SetString(point.description.c_str(), point.description.size());
        
        element.AddMember("position", position, allocator);
        element.AddMember("name", name, allocator);
        element.AddMember("description", desc, allocator);
        
        jsonDocument.PushBack(element, allocator);
    }
    rapidjson::StringBuffer buf(&allocatorCrt);
    rapidjson::Writer<rapidjson::StringBuffer> writer (buf, &allocatorCrt);

    jsonDocument.Accept(writer);
    outString = std::string(buf.GetString(), buf.GetSize());

}