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


C++ JsonArray类代码示例

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


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

示例1: Save

bool TournamentConfig::Save(const std::string &fileName)
{
    bool ret = true;

    JsonObject json;

    json.AddValue("version", TOURNAMENT_CONFIG_VERSION);

    JsonArray tournament;
    for (std::vector<Tarot::Distribution>::iterator iter =  mOptions.turns.begin(); iter !=  mOptions.turns.end(); ++iter)
    {
        std::string type;
        std::string file;
        std::uint32_t number = 0U;
        JsonObject obj;

        if (iter->mType == Tarot::Distribution::RANDOM_DEAL)
        {
            type = "random";
            file = "";
        }
        else if (iter->mType == Tarot::Distribution::CUSTOM_DEAL)
        {
            type = "custom";
            file = iter->mFile;
        }
        else
        {
            type = "numbered";
            number = iter->mSeed;
        }

        obj.AddValue("type", type);
        obj.AddValue("file", file);
        obj.AddValue("number", number);
        tournament.AddValue(obj);
    }
    json.AddValue("tournament", tournament);

    if (!JsonWriter::SaveToFile(json, fileName))
    {
        ret = false;
        TLogError("Saving tournament's configuration failed.");
    }
    return ret;
}
开发者ID:belegar,项目名称:tarotclub,代码行数:46,代码来源:TournamentConfig.cpp

示例2: load_technique

void load_technique(JsonObject &jo)
{
    ma_technique tec;

    tec.id = jo.get_string("id");
    //tec.name = _(jo.get_string("name").c_str());

    JsonArray jsarr = jo.get_array("messages");
    while (jsarr.has_more()) {
        tec.messages.push_back(_(jsarr.next_string().c_str()));
    }

    tec.reqs.unarmed_allowed = jo.get_bool("unarmed_allowed", false);
    tec.reqs.melee_allowed = jo.get_bool("melee_allowed", false);
    tec.reqs.min_melee = jo.get_int("min_melee", 0);
    tec.reqs.min_unarmed = jo.get_int("min_unarmed", 0);
    tec.reqs.req_buffs = jo.get_tags("req_buffs");

    tec.crit_tec = jo.get_bool("crit_tec", false);
    tec.defensive = jo.get_bool("defensive", false);
    tec.disarms = jo.get_bool("disarms", false);
    tec.grabs = jo.get_bool("grabs", false);
    tec.counters = jo.get_bool("counters", false);
    tec.miss_recovery = jo.get_bool("miss_recovery", false);
    tec.grab_break = jo.get_bool("grab_break", false);
    tec.flaming = jo.get_bool("flaming", false);
    tec.quick = jo.get_bool("quick", false);

    tec.hit = jo.get_int("pain", 0);
    tec.bash = jo.get_int("bash", 0);
    tec.cut = jo.get_int("cut", 0);
    tec.pain = jo.get_int("pain", 0);

    tec.bash_mult = jo.get_float("bash_mult", 1.0);
    tec.cut_mult = jo.get_float("cut_mult", 1.0);

    tec.down_dur = jo.get_int("down_dur", 0);
    tec.stun_dur = jo.get_int("stun_dur", 0);
    tec.knockback_dist = jo.get_int("knockback_dist", 0);
    tec.knockback_spread = jo.get_int("knockback_spread", 0);

    tec.aoe = jo.get_string("aoe", "");
    tec.flags = jo.get_tags("flags");

    ma_techniques[tec.id] = tec;
}
开发者ID:9600bauds,项目名称:Cataclysm-DDA,代码行数:46,代码来源:martialarts.cpp

示例3: flags_from_json

unsigned Item_factory::flags_from_json(JsonObject& jo, std::string member, std::string flag_type)
{
    //If none is found, just use the standard none action
    unsigned flag = 0;
    //Otherwise, grab the right label to look for
    if ( jo.has_array(member) ) {
        JsonArray jarr = jo.get_array(member);
        while (jarr.has_more()){
            set_flag_by_string(flag, jarr.next_string(), flag_type);
        }
    } else if ( jo.has_string(member) ) {
        //we should have gotten a string, if not an array
        set_flag_by_string(flag, jo.get_string(member), flag_type);
    }

    return flag;
}
开发者ID:CepheidVar,项目名称:Cataclysm-DDA,代码行数:17,代码来源:item_factory.cpp

示例4: onError

void
StratumConnection::getAddressHistory(
    const bc::client::obelisk_codec::error_handler &onError,
    const bc::client::obelisk_codec::fetch_history_handler &onReply,
    const bc::payment_address &address, size_t fromHeight)
{
    JsonArray params;
    params.append(json_string(address.encoded().c_str()));

    auto errorShim = [onError](Status status)
    {
        onError(std::make_error_code(std::errc::bad_message));
    };

    auto decoder = [onReply](JsonPtr payload) -> Status
    {
        JsonArray arrayJson(payload);

        bc::client::history_list history;
        size_t size = arrayJson.size();
        history.reserve(size);
        for (size_t i = 0; i < size; i++)
        {
            struct HistoryJson:
                public JsonObject
            {
                ABC_JSON_CONSTRUCTORS(HistoryJson, JsonObject)
                ABC_JSON_STRING(txid, "tx_hash", nullptr)
                ABC_JSON_INTEGER(height, "height", 0)
            };
            HistoryJson json(arrayJson[i]);

            bc::hash_digest hash;
            if (!json.txidOk() || !bc::decode_hash(hash, json.txid()))
                return ABC_ERROR(ABC_CC_Error, "Bad txid");

            bc::client::history_row row;
            row.output.hash = hash;
            row.output_height = json.height();
            row.spend.hash = bc::null_hash;
            history.push_back(row);
        }

        onReply(history);
        return Status();
    };
开发者ID:MoeAfilal,项目名称:airbitz-core,代码行数:46,代码来源:StratumConnection.cpp

示例5: set_material_from_json

void Item_factory::set_material_from_json(JsonObject& jo, std::string member, itype* new_item_template)
{
    //If the value isn't found, just return a group of null materials
    std::string material_list[2] = {"null", "null"};
    if( jo.has_array(member) ) {
        JsonArray jarr = jo.get_array(member);
        if (jarr.size() > 2) {
            debugmsg("Too many materials provided for item %s", new_item_template->id.c_str());
        }
        material_list[0] = jarr.get_string(0);
        material_list[1] = jarr.get_string(1);
    } else if ( jo.has_string(member) ) {
        material_list[0] = jo.get_string(member);
    }
    new_item_template->m1 = material_list[0];
    new_item_template->m2 = material_list[1];
}
开发者ID:CepheidVar,项目名称:Cataclysm-DDA,代码行数:17,代码来源:item_factory.cpp

示例6: QPixmap

QPixmap QSanRoomSkin::getProgressBarPixmap(int percentile) const
{
    QVariant allMaps_var = _m_imageConfig[S_SKIN_KEY_PROGRESS_BAR_IMAGE];
    if (!allMaps_var.canConvert<JsonArray>())
        return QPixmap(1, 1);

    JsonArray allMaps = allMaps_var.value<JsonArray>();

    for (int i = 0; i < allMaps.size(); i++) {
        if (!isNumber(allMaps[i].value<JsonArray>()[0])) continue;
        int thred = allMaps[i].value<JsonArray>()[0].toInt();
        if (thred >= percentile) {
            if (!isString(allMaps[i].value<JsonArray>()[1])) continue;
            return getPixmapFromFileName(allMaps[i].value<JsonArray>()[1].toString(), true);
        }
    }
    return QPixmap(1, 1);
}
开发者ID:chenchizhao,项目名称:QSanguosha-v2,代码行数:18,代码来源:skin-bank.cpp

示例7: QColor

bool IQSanComponentSkin::QSanShadowTextFont::tryParse(const QVariant &arg)
{
    if (!arg.isValid() || !arg.canConvert<JsonArray>()) return false;
    JsonArray args = arg.value<JsonArray>();
    if (args.size() < 4) return false;
    if (!QSanSimpleTextFont::tryParse(arg)) return false;
    if (args.size() >= 8) {
        m_shadowRadius = args[4].toInt();
        m_shadowDecadeFactor = args[5].toDouble();
        JsonUtils::tryParse(args[6], m_shadowOffset);

        JsonArray color = args[7].value<JsonArray>();
        m_shadowColor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt(), color[3].toInt());
    } else {
        m_shadowRadius = -1;
    }
    return true;
}
开发者ID:chenchizhao,项目名称:QSanguosha-v2,代码行数:18,代码来源:skin-bank.cpp

示例8: run_iterator_test

static void run_iterator_test() {
  StaticJsonDocument<JSON_ARRAY_SIZE(2)> doc;
  JsonArray array = doc.to<JsonArray>();
  array.add(12);
  array.add(34);

  TIterator it = array.begin();
  TIterator end = array.end();

  REQUIRE(end != it);
  REQUIRE(12 == it->template as<int>());
  REQUIRE(12 == static_cast<int>(*it));
  ++it;
  REQUIRE(end != it);
  REQUIRE(34 == it->template as<int>());
  REQUIRE(34 == static_cast<int>(*it));
  ++it;
  REQUIRE(end == it);
}
开发者ID:anhtuan200794,项目名称:libraries,代码行数:19,代码来源:iterator.cpp

示例9: testComplexObject

/*
 * Test a complex object.
 */
void JsonTest::testComplexObject() {
  JsonObject object;
  object.Add("age", 10);
  object.Add("name", "simon");
  object.Add("male", true);

  JsonArray *array = object.AddArray("lucky numbers");
  array->Append(2);
  array->Append(5);

  string expected = (
      "{\n"
      "  \"age\": 10,\n"
      "  \"lucky numbers\": [2, 5],\n"
      "  \"male\": true,\n"
      "  \"name\": \"simon\"\n"
      "}");
  OLA_ASSERT_EQ(expected, JsonWriter::AsString(object));
}
开发者ID:mlba-team,项目名称:open-lighting,代码行数:22,代码来源:JsonTest.cpp

示例10: key

void sfx::load_sound_effects( JsonObject &jsobj )
{
    if( !sound_init_success ) {
        return;
    }
    const id_and_variant key( jsobj.get_string( "id" ), jsobj.get_string( "variant", "default" ) );
    const int volume = jsobj.get_int( "volume", 100 );
    auto &effects = sfx_resources.sound_effects[ key ];

    JsonArray jsarr = jsobj.get_array( "files" );
    while( jsarr.has_more() ) {
        sound_effect new_sound_effect;
        const std::string file = jsarr.next_string();
        new_sound_effect.volume = volume;
        new_sound_effect.resource_id = add_sfx_path( file );

        effects.push_back( new_sound_effect );
    }
}
开发者ID:ymber,项目名称:Cataclysm-DDA,代码行数:19,代码来源:sdlsound.cpp

示例11: JsonObject

void CreateProc::_ResizeFiles()
{
    AppSetting *setting = AppSetting::Instance();

    JsonObject *projData = new JsonObject();
    projData->Add("pid",_pid);

    JsonArray *pages = new JsonArray();
    projData->AddObject("pages", pages);

    for (auto fileItor = _filesMapping->begin(); fileItor != _filesMapping->end(); ++fileItor)
    {
        JsonObject *singleFile = new JsonObject();

        string srcFilename = FileSys::GetFilename(fileItor->first);
        string saveFilename = FileSys::GetFilename(fileItor->second);
        string fileExtension = FileSys::GetFileExtension(fileItor->first);

        singleFile->Add("filename", srcFilename);
        singleFile->Add("imagedir", fileItor->first);

        for (auto sizeItor = setting->pic_size->begin(); sizeItor != setting->pic_size->end(); ++sizeItor)
        {
            string optDir = FileSys::FormatDir(setting->file_save_dir + _zipRandName + "/" + sizeItor->first);
            FileSys::CreateDirectory(optDir);

            //  Resize Picture, but need to rename
            saveFilename = Assist::GenerateRandomFilename(saveFilename) + fileExtension;
            OpencvEx::ResizePictureFile(fileItor->second, optDir + saveFilename, sizeItor->second->x, sizeItor->second->y);

            singleFile->Add("image" + sizeItor->first, optDir + saveFilename);
        }

        pages->AddObject(singleFile);
        safe_del(singleFile);
    }

    //  push to server
    _PushJsonToServer(projData->ToString());

    safe_del(pages);
    safe_del(projData);
}
开发者ID:woudX,项目名称:ServerPic,代码行数:43,代码来源:createproc.cpp

示例12: is_mod_target

bool Item_factory::is_mod_target(JsonObject& jo, std::string member, std::string weapon)
{
    //If none is found, just use the standard none action
    unsigned is_included = false;
    //Otherwise, grab the right label to look for
    if ( jo.has_array(member) ) {
        JsonArray jarr = jo.get_array(member);
        while (jarr.has_more() && is_included == false){
            if (jarr.next_string() == weapon){
                is_included = true;
            }
        }
    } else {
        if (jo.get_string(member) == weapon){
            is_included = true;
        }
    }
    return is_included;
}
开发者ID:nickasummers,项目名称:Cataclysm-DDA,代码行数:19,代码来源:item_factory.cpp

示例13: save

bool EffectHandler::save(JsonArray& array, uint8_t ID, const char * name)
{
	//Serial.printf("[EffectHandler::save] Effect = %s, ID = %s\n", _name, ID);

	int index = 0;

	for (JsonArray::iterator it = array.begin(); it != array.end(); ++it) {
		// *it contains the JsonVariant which can be casted as usuals
		//const char* value = *it;

		JsonObject& preset = *it;

		if (preset.containsKey("ID")) {

			if ( preset["ID"] == ID) {
				array.removeAt(index) ;
				DebugEffectHandlerf("[EffectHandler::save] preset %u removed\n", ID);
				break; 
			}

		}

		index++;
		// this also works:
		//value = it->as<const char*>();

	}

	JsonObject& current = array.createNestedObject();

	current["ID"] = ID;
	current["name"] = name;
	current["effect"] = _name;

	if (addJson(current)) {
		return true;
	} else {
		return false;
	}


};
开发者ID:jpfy,项目名称:Melvanimate,代码行数:42,代码来源:EffectHandler.cpp

示例14: while

void MonsterGroupManager::LoadMonsterGroup(JsonObject &jo)
{
    MonsterGroup g;

    g.name = jo.get_string("name");
    g.defaultMonster = jo.get_string("default");
    if (jo.has_array("monsters")){
        JsonArray monarr = jo.get_array("monsters");

        while (monarr.has_more()) {
            JsonObject mon = monarr.next_object();
            std::string name = mon.get_string("monster");
            int freq = mon.get_int("freq");
            int cost = mon.get_int("cost_multiplier");
            int pack_min = 1;
            int pack_max = 1;
            if(mon.has_member("pack_size")){
                JsonArray packarr = mon.get_array("pack_size");
                pack_min = packarr.next_int();
                pack_max = packarr.next_int();
            }
            int starts = 0;
            int ends = 0;
            if(mon.has_member("starts")){
                starts = mon.get_int("starts");
            }
            if(mon.has_member("ends")){
                ends = mon.get_int("ends");
            }
            MonsterGroupEntry new_mon_group = MonsterGroupEntry(name,freq,cost,pack_min,pack_max,starts,ends);
            if(mon.has_member("conditions")){
              JsonArray conditions_arr = mon.get_array("conditions");
              while(conditions_arr.has_more()){
                new_mon_group.conditions.push_back(conditions_arr.next_string());
              }
            }
            g.monsters.push_back(new_mon_group);
        }
    }

    monsterGroupMap[g.name] = g;
}
开发者ID:9600bauds,项目名称:Cataclysm-DDA,代码行数:42,代码来源:mongroupdef.cpp

示例15: loginServerMessages

Status
loginServerMessages(JsonPtr &result, const std::list<std::string> &usernames)
{
    const auto url = ABC_SERVER_ROOT "/v2/messages";

    // Compute all userIds:
    JsonArray loginIds;
    std::map<std::string, std::string> loginIdMap;
    for (const auto &username: usernames)
    {
        std::shared_ptr<LoginStore> store;
        ABC_CHECK(LoginStore::create(store, username));
        const auto loginId = base64Encode(store->userId());
        loginIds.append(json_string(loginId.c_str()));
        loginIdMap[loginId] = username;
    }

    JsonObject request;
    ABC_CHECK(request.set("loginIds", loginIds));

    // Make the request:
    HttpReply reply;
    ABC_CHECK(AirbitzRequest().request(reply, url, "POST", request.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    // Insert the original usernames into the results:
    JsonArray arrayJson(replyJson.results());
    size_t size = arrayJson.size();
    for (size_t i = 0; i < size; i++)
    {
        JsonObject objectJson(arrayJson[i]);
        const auto loginId = objectJson.getString("loginId", nullptr);
        if (!loginId) continue;
        const auto username = loginIdMap.find(loginId);
        if (username == loginIdMap.end()) continue;
        ABC_CHECK(objectJson.set("username", username->second));
    }

    result = arrayJson;
    return Status();
}
开发者ID:Airbitz,项目名称:airbitz-core,代码行数:42,代码来源:LoginServer.cpp


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