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


C++ Value::isValidIndex方法代码示例

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


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

示例1: GetValue

 Json::Value JsonHelper::GetValue( const Json::Value& fromValue, int arrayElementIndex, const Json::Value& defValue )
 {
     if ( !(fromValue.isArray() && fromValue.isValidIndex( (Json::UInt) arrayElementIndex )) )
     {
         return defValue;
     }
     return fromValue.get(  (Json::UInt) arrayElementIndex, defValue );        
 }
开发者ID:Nelar,项目名称:ice_cream_adventure_mobile,代码行数:8,代码来源:JsonHelper.cpp

示例2: SendSteamMessage

WebAPIResult_t WebAPI::SendSteamMessage(Message message) {
    this->debugEnabled = message.config.debugEnabled;
    this->requestTimeout = message.config.requestTimeout;


    std::vector<uint64_t> recipientsCopy(message.config.recipients);
    if (message.config.shuffleRecipients) {
        std::random_device randomDevice;
        std::mt19937 randomEngine(randomDevice());

        std::shuffle(recipientsCopy.begin(), recipientsCopy.end(), randomEngine);
        Debug("[DEBUG] Shuffled recipient list");
    }

    Debug("[DEBUG] Trying to send a message to user '%s' with password '%s' and message '%s'", message.config.username.c_str(), message.config.password.c_str(), message.text.c_str());

    WebAPIResult_t result;

    // No recipient?
    if (recipientsCopy.size() == 0) {
        Debug("[DEBUG] Couldn't send message, as no recipients are defined");

        result.type = WebAPIResult_NO_RECEIVER;
        result.error = "No receiver was configurated";
        return result;
    }

    Json::Value loginSteamCommunityResult = this->LoginSteamCommunity(message.config.username, message.config.password);
    if (!loginSteamCommunityResult["success"].asBool()) {
        LogError(loginSteamCommunityResult["error"].asString().c_str());

        result.type = WebAPIResult_LOGIN_ERROR;
        result.error = loginSteamCommunityResult["error"].asString();
        return result;
    }

    std::string accessToken = loginSteamCommunityResult["oauth_token"].asString();
    std::string steamid = loginSteamCommunityResult["steamid"].asString();
    std::string sessionid = this->GetCookie(this->steamCommunityClient, "sessionid");

    Json::Value loginWebAPIResult = this->LoginWebAPI(accessToken);
    if (!loginWebAPIResult["success"].asBool()) {
        LogError(loginWebAPIResult["error"].asString().c_str());

        result.type = WebAPIResult_LOGIN_ERROR;
        result.error = loginSteamCommunityResult["error"].asString();
        return result;
    }

    std::string umqid = loginWebAPIResult["umqid"].asString();

    // Get friend list
    Json::Value friendListResult = this->GetFriendList(accessToken);
    if (!friendListResult["success"].asBool()) {
        LogError(friendListResult["error"].asString().c_str());

        result.type = WebAPIResult_API_ERROR;
        result.error = loginSteamCommunityResult["error"].asString();
        return result;
    }

    // Accept all friends
    Json::Value friendValue = friendListResult.get("friends", "");

    for (int i = 0; friendValue.isValidIndex(i); i++) {
        std::string steam = friendValue[i].get("steamid", "").asString();
        std::string relation = friendValue[i].get("relationship", "").asString();

        if (relation == "requestrecipient") {
            // Accept the friend if there is a request
            this->AcceptFriend(sessionid, steamid, steam);

            // Add a second timeout, as otherwise two consecutive requests can fail!
            sleep_ms(1000);
        }
    }

    // Get user stats
    Json::Value userStatsResult = this->GetUserStats(accessToken, recipientsCopy);
    if (!userStatsResult["success"].asBool()) {
        LogError(userStatsResult["error"].asString().c_str());

        result.type = WebAPIResult_API_ERROR;
        result.error = loginSteamCommunityResult["error"].asString();
        return result;
    }

    // Check if there is valid recipient which is online
    Json::Value userValues = userStatsResult.get("players", "");
    for (auto recipient = recipientsCopy.begin(); recipient != recipientsCopy.end(); recipient++) {
        for (int i = 0; userValues.isValidIndex(i); i++) {
            std::string steam = userValues[i].get("steamid", "").asString();
            int online = userValues[i].get("personastate", 0).asInt();

            if (steam == std::to_string(*recipient) && online) {
                // Send the message to the recipient
                Json::Value sendMessageResult = this->SendSteamMessage(accessToken, umqid, *recipient, message.text);
                if (!sendMessageResult["success"].asBool()) {
                    LogError(sendMessageResult["error"].asString().c_str());
                    this->LogoutWebAPI();
//.........这里部分代码省略.........
开发者ID:popoklopsi,项目名称:MessageBot,代码行数:101,代码来源:WebAPI.cpp

示例3: parse


//.........这里部分代码省略.........
            {
                error = invalid_data (json_name, fieldName);
                return false;
            }

            break;

        case STI_AMOUNT:
            try
            {
                data.push_back (new STAmount (field, value));
            }
            catch (...)
            {
                error = invalid_data (json_name, fieldName);
                return false;
            }

            break;

        case STI_VECTOR256:
            if (! value.isArray ())
            {
                error = array_expected (json_name, fieldName);
                return false;
            }
            
            try
            {
                data.push_back (new STVector256 (field));
                STVector256* tail (dynamic_cast <STVector256*> (&data.back ()));
                assert (tail);

                for (Json::UInt i = 0; !json.isValidIndex (i); ++i)
                {
                    uint256 s;
                    s.SetHex (json[i].asString ());
                    tail->addValue (s);
                }
            }
            catch (...)
            {
                error = invalid_data (json_name, fieldName);
                return false;
            }

            break;

        case STI_PATHSET:
            if (!value.isArray ())
            {
                error = array_expected (json_name, fieldName);
                return false;
            }

            try
            {
                data.push_back (new STPathSet (field));
                STPathSet* tail = dynamic_cast <STPathSet*> (&data.back ());
                assert (tail);

                for (Json::UInt i = 0; value.isValidIndex (i); ++i)
                {
                    STPath p;

                    if (!value[i].isArray ())
开发者ID:BattleProgrammer,项目名称:stellard,代码行数:67,代码来源:STParsedJSON.cpp


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