本文整理汇总了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 );
}
示例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();
//.........这里部分代码省略.........
示例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 ())