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


C++ JsonArray::at方法代码示例

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


在下文中一共展示了JsonArray::at方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: isNumberArray

bool JsonUtils::isNumberArray(const QVariant &var, unsigned from, unsigned to)
{
    if (!var.canConvert<JsonArray>())
        return false;

    JsonArray array = var.value<JsonArray>();

    if ((unsigned)array.length() <= to)
        return false;
    for (unsigned int i = from; i <= to; i++) {
        if (!array.at(i).canConvert<int>())
            return false;
    }
    return true;
}
开发者ID:Xusine1131,项目名称:QSanguosha-DGAH,代码行数:15,代码来源:json.cpp

示例2: writeJson

bool JsonHelper::writeJson(JsonArray json, string path)
{
    if(!validatePathExtension(path))
    {
        return false;
    }

    string arrayString = "[";
    size_t jsonSize = json.size();
    for(size_t i = 0; i < jsonSize; ++i)
    {
        arrayString += "\n" + dump(json.at(i).object_items(), 1);
        if(i != jsonSize - 1)
        {
            arrayString += ",";
        }
    }
    arrayString += "\n]";

    ofstream JsonSaveFile(path);
    JsonSaveFile << arrayString;
    JsonSaveFile.close();
    return true;
}
开发者ID:ShiftMediaProject,项目名称:x265,代码行数:24,代码来源:JsonHelper.cpp

示例3: initialize

void RecAnalysis::initialize(QString dir)
{
    QList<QByteArray> records_line;
    if (dir.isEmpty()) {
        records_line = ClientInstance->getRecords();
    } else if (dir.endsWith(".qsgs")) {
        QFile file(dir);
        if (file.open(QIODevice::ReadOnly)) {
            char header;
            file.getChar(&header);
            if (header == 0) {
                QByteArray lines = file.readAll();
                lines = qUncompress(lines);
                records_line = lines.split('\n');
            } else {
                file.ungetChar(header);
                while (!file.atEnd())
                    records_line << file.readLine();
            }
        }
    } else {
        QMessageBox::warning(NULL, tr("Warning"), tr("The file is unreadable"));
        return;
    }
    records_line.removeAll(QByteArray());

    QStringList role_list;
    foreach (const QByteArray &_line, records_line) {
        QByteArray line = _line;
        line.remove(0, line.indexOf(' '));

        Packet packet;
        if (!packet.parse(line))
            continue;

        if (packet.getCommandType() == S_COMMAND_SETUP) {
            const QVariant &body = packet.getMessageBody();
            if (JsonUtils::isString(body)) {
                QString l = body.toString();
                QRegExp rx("(.*):(@?\\w+):(\\d+):(\\d+):([+\\w-]*):([RCFSTBHAMN123a-r]*)(\\s+)?");
                if (!rx.exactMatch(l))
                    continue;

                QStringList texts = rx.capturedTexts();
                m_recordGameMode = texts.at(2);
                m_recordPlayers = texts.at(2).split("_").first().remove(QRegExp("[^0-9]")).toInt();
                QStringList ban_packages = texts.at(5).split("+");
                foreach (const Package *package, Sanguosha->getPackages()) {
                    if (!ban_packages.contains(package->objectName())
                        && Sanguosha->getScenario(package->objectName()) == NULL)
                        m_recordPackages << Sanguosha->translate(package->objectName());
                }

                QString flags = texts.at(6);
                if (flags.contains("R")) m_recordServerOptions << tr("RandomSeats");
                if (flags.contains("C")) m_recordServerOptions << tr("EnableCheat");
                if (flags.contains("F")) m_recordServerOptions << tr("FreeChoose");
                if (flags.contains("S")) m_recordServerOptions << tr("Enable2ndGeneral");
                if (flags.contains("A")) m_recordServerOptions << tr("EnableAI");

                continue;
            }
        }

        if (packet.getCommandType() == S_COMMAND_ARRANGE_SEATS) {
            role_list.clear();
            JsonUtils::tryParse(packet.getMessageBody(), role_list);
            continue;
        }

        if (packet.getCommandType() == S_COMMAND_ADD_PLAYER) {
            JsonArray body = packet.getMessageBody().value<JsonArray>();
            if (body.size() >= 2) {
                getPlayer(body[0].toString())->m_screenName = body[1].toString();
            }
            continue;
        }

        if (packet.getCommandType() == S_COMMAND_REMOVE_PLAYER) {
            QString name = packet.getMessageBody().toString();
            m_recordMap.remove(name);
            continue;
        }

        if (packet.getCommandType() == S_COMMAND_SET_PROPERTY) {
            QStringList self_info;
            if (!JsonUtils::tryParse(packet.getMessageBody(), self_info) || self_info.size() < 3)
                continue;

            const QString &who = self_info.at(0);
            const QString &property = self_info.at(1);
            const QString &value = self_info.at(2);

            if (who == S_PLAYER_SELF_REFERENCE_ID) {
                if (property == "objectName") {
                    getPlayer(value, S_PLAYER_SELF_REFERENCE_ID)->m_screenName = Config.UserName;
                } else if (property == "role") {
                    getPlayer(S_PLAYER_SELF_REFERENCE_ID)->m_role = value;
                } else if (property == "general") {
                    getPlayer(S_PLAYER_SELF_REFERENCE_ID)->m_generalName = value;
//.........这里部分代码省略.........
开发者ID:DGAH,项目名称:QSanguosha-PK,代码行数:101,代码来源:record-analysis.cpp


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