本文整理汇总了C++中json::Value::isArray方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::isArray方法的具体用法?C++ Value::isArray怎么用?C++ Value::isArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::isArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tryParse
bool CardsMoveStruct::tryParse(const Json::Value &arg) {
if (!arg.isArray() || arg.size() != 8) return false;
if ((!arg[0].isInt() && !arg[0].isArray()) ||
!isIntArray(arg, 1, 2) || !isStringArray(arg, 3, 6)) return false;
if (arg[0].isInt()) {
int size = arg[0].asInt();
for (int i = 0; i < size; i++)
card_ids.append(Card::S_UNKNOWN_CARD_ID);
} else if (!QSanProtocol::Utils::tryParse(arg[0], card_ids))
return false;
from_place = (Player::Place)arg[1].asInt();
to_place = (Player::Place)arg[2].asInt();
from_player_name = toQString(arg[3]);
to_player_name = toQString(arg[4]);
from_pile_name = toQString(arg[5]);
to_pile_name = toQString(arg[6]);
reason.tryParse(arg[7]);
return true;
}
示例2: if
bool QSanProtocol::Countdown::tryParse(Json::Value val) {
if (!val.isArray() || (val.size() != 2 && val.size() != 3) ||
!val[0].isString() || val[0].asString() != S_COUNTDOWN_MAGIC)
return false;
if (val.size() == 3) {
if (!Utils::isIntArray(val, 1, 2)) return false;
m_current = (time_t)val[1].asInt();
m_max = (time_t)val[2].asInt();
m_type = S_COUNTDOWN_USE_SPECIFIED;
return true;
} else if (val.size() == 2) {
CountdownType type = (CountdownType)val[1].asInt();
if (type != S_COUNTDOWN_NO_LIMIT && type != S_COUNTDOWN_USE_DEFAULT)
return false;
else m_type = type;
return true;
} else
return false;
}
示例3: Load
void PossibleRooms::Load( Json::Value const& possibleRooms )
{
mRoomIds.clear();
if (possibleRooms.isArray())
{
for (auto& possibleRoom : possibleRooms)
{
std::string roomIdStr;
int32_t chance;
if (Json::GetStr( possibleRoom["room_id"], roomIdStr ) && Json::GetInt( possibleRoom["weight"], chance ))
{
int32_t isBase = 1;
Json::GetInt( possibleRoom["base"], isBase );
AddPossibleRoom( AutoId( roomIdStr ), chance, isBase==1 );
}
}
}
mUniqueRoomIds = MakeRoomeIdsUnique( mRoomIds );
}
示例4: ParseTeamInfosJson
bool ParseTeamInfosJson(const std::string& team_infos_json, bool include_invalid_team, std::list<TeamInfo>& team_infos)
{
Json::Value json;
Json::Reader reader;
if (reader.parse(team_infos_json, json) && json.isArray())
{
int len = json.size();
for (int i = 0; i < len; i++)
{
TeamInfo info;
ParseTeamInfoJson(json[i], info);
if (info.IsValid() || (!info.IsValid() && include_invalid_team))
team_infos.push_back(info);
}
return true;
}
return false;
}
示例5: if
bool k8s_api_handler::handle_component(const Json::Value& json, const msg_data* data)
{
m_error = false;
if(!json.isNull())
{
if(json.isArray())
{
for(const auto& version : json)
{
if(version.isConvertibleTo(Json::stringValue))
{
m_extensions.push_back(version.asString());
}
else
{
g_logger.log("K8s API handler error: could not extract API versions or extensions from JSON.",
sinsp_logger::SEV_ERROR);
m_error = true;
return false;
}
}
}
else if(json.isConvertibleTo(Json::stringValue))
{
m_extensions.push_back(json.asString());
}
else
{
g_logger.log("K8s API handler error: could not extract API versions or extensions from JSON.",
sinsp_logger::SEV_ERROR);
m_error = true;
return false;
}
m_data_received = true;
}
else
{
g_logger.log("K8s API handler error: json is null.", sinsp_logger::SEV_ERROR);
m_error = true;
return false;
}
return true;
}
示例6: GetComponents
TEST_F(GetComponentsTest, PositiveExecute) {
compute::json::GetComponents command_json;
GetComponents* command = new GetComponents("");
EXPECT_NO_THROW(command_json.set_command(command));
Json::Value params;
Json::Value result;
params["id"] = "";
EXPECT_NO_THROW(command_json.method(params, result));
ASSERT_TRUE(result.isArray());
ASSERT_EQ(result.size(), 10);
for (std::uint32_t i = 0; i < 10; ++i) {
ASSERT_EQ(result[i]["component"].asString(), std::to_string(i));
}
}
示例7: handle_groups
bool mesos_state_t::handle_groups(const Json::Value& root, marathon_group::ptr_t to_group, const std::string& framework_id)
{
Json::Value groups = root["groups"];
if(!groups.isNull() && groups.isArray())
{
for(const auto& group : groups)
{
to_group = add_group(group, to_group, framework_id);
ASSERT(to_group);
handle_groups(group, to_group, framework_id);
}
}
else
{
g_logger.log("No groups found.", sinsp_logger::SEV_WARNING);
return false;
}
return true;
}
示例8: setLaserPulses
void jsonParser::setLaserPulses(Json::Value &document, EM_FIELD *emfield){
std::string name1 = _JSON_OBJ_ARRAY_LASER_;
Json::Value lasers;
if (setValue(lasers, document, name1.c_str())) {
if (lasers.isArray()){
std::string name2;
for (unsigned int index = 0; index < lasers.size(); index++){
Json::Value myLaser = lasers[index];
name2 = _JSON_BOOL_ENABLED;
bool enabled = false;
setBool(&enabled, myLaser, name2.c_str());
if (enabled){
laserPulse *pulse1 = new(laserPulse);
laserPulseBoolFlags flags;
flags.type = setLaserType(pulse1, myLaser);
flags.pol = setLaserPolarization(pulse1, myLaser);
flags.duration = setLaserDurationFWHM(pulse1, myLaser);
flags.initialPosition = setLaserInitialPosition(pulse1, myLaser);
flags.a = setLaserAmplitude(pulse1, myLaser);
flags.waist = setLaserWaist(pulse1, myLaser);
flags.focusPosition = setLaserFocusPosition(pulse1, myLaser);
flags.rotation = setLaserRotation(pulse1, myLaser);
flags.lambda = setLaserLambda(pulse1, myLaser);
flags.riseTime = setLaserRiseTime(pulse1, myLaser);
if (checkLaserBoolFlags(flags, pulse1)){
emfield->addPulse(pulse1);
}
else if (isThisJsonMaster){
std::cout << "warning: laser #" << index << " is incorrectly defined\n";
}
delete pulse1;
}
}
}
}
}
示例9: OnMapLoad
void MapSystem::OnMapLoad( core::MapLoadEvent const& Evt )
{
ClearMapElements();
PathVect_t Paths;
Filesys& FSys = Filesys::Get();
FSys.GetFileNames( Paths, Evt.mMapName );
for( PathVect_t::const_iterator i = Paths.begin(), e = Paths.end(); i != e; ++i )
{
boost::filesystem::path const& Path = *i;
PathVect_t LevelPaths;
FSys.GetFileNames( LevelPaths, Path );
if( Path.extension().string() != ".json" )
{
continue;
}
AutoFile JsonFile = FSys.Open( *i );
if( !JsonFile.get() )
{
continue;
}
JsonReader Reader( *JsonFile );
if( !Reader.IsValid() )
{
continue;
}
Json::Value Root = Reader.GetRoot();
if( !Root.isArray() )
{
continue;
}
for( Json::Value::iterator i = Root.begin(), e = Root.end(); i != e; ++i )
{
Json::Value& mapElementDesc = *i;
if( !AddMapElementFromOneTextureDesc( mapElementDesc ) )
{
return;
}
}
}
EventServer<core::MapLoadedEvent>::Get().SendEvent( core::MapLoadedEvent() );
}
示例10: is_defeated_npc
bool war_story::is_defeated_npc(int player_id, int map_id, int npc_id) const
{
na::file_system::json_value_map::const_iterator it = _maps.find(map_id);
if(it!=_maps.end())
{
Json::Value progress = get_player_progress(player_id,map_id);
Json::Value arr = progress[sg::story_def::defeated_list];
if(!arr.isArray()) return false;
for (Json::Value::iterator i = arr.begin();i!=arr.end();++i)
{
Json::Value defeated_info = *i;
int _id = defeated_info[sg::army_def::army_id].asInt();
if(npc_id==_id)
{
return true;
}
}
}
return false;
}
示例11: Exception
/**
* Returns Point3 structure for give input json array
*/
Eigen::Vector3f SkeletonRepresentationJSON::jsonGetPoint3(const Json::Value &jsonValue)
{
Eigen::Vector3f point = Eigen::Vector3f::Zero();
if (jsonValue.isNull()) return Eigen::Vector3f();
if (jsonValue.isArray() && jsonValue.size() == 3)
{
Json::ValueIterator it = jsonValue.begin();
point[0] = static_cast<float>((*it).asFloat());
it++;
point[1] = static_cast<float>((*it).asFloat());
it++;
point[2] = static_cast<float>((*it).asFloat());
}
else
return point;//throw Exception("Error in PoseSet::jsonGetPoint3(): value size = %d", jsonValue.size());
return point;
}
示例12: renderFromJSON
void Game::renderFromJSON(const Json::Value &msgs) {
invariant(msgs.isArray(), "json messages must be array");
invariant(msgs.size() > 0, "messges must be nonempty");
for (auto msg : msgs) {
auto type = must_have_idx(msg, "type").asString();
if (type == "render") {
handleRenderMessage(msg);
} else if (type == "start") {
Renderer::get()->setGameTime(0.f);
Renderer::get()->setTimeMultiplier(1.f);
} else if (type == "game_over") {
// TODO(zack/connor): do more here
auto winning_team = toID(must_have_idx(msg, "winning_team"));
LOG(DEBUG) << "Winning team : " << winning_team << '\n';
running_ = false;
} else {
invariant_violation("unknown message type: " + type);
}
}
}
示例13: GetCollection
TEST_F(GetCollectionTest, PositiveExecute) {
compute::json::GetCollection command_json;
GetCollection* command = new GetCollection("TestModuleId", "TestName");
EXPECT_NO_THROW(command_json.set_command(command));
Json::Value params;
Json::Value result;
params["component"] = "TestModuleId";
params["name"] = "TestName";
EXPECT_NO_THROW(command_json.method(params, result));
ASSERT_TRUE(result.isArray());
ASSERT_EQ(result.size(), 10);
for (std::uint32_t i = 0; i < 10; ++i) {
ASSERT_EQ(result[i]["subcomponent"].asString(), std::to_string(i));
}
}
示例14: LoadJson
bool cMotion::LoadJson(const Json::Value& root)
{
bool succ = true;
if (!root[gLoopKey].isNull())
{
mLoop = root[gLoopKey].asBool();
}
if (!root[gFrameKey].isNull())
{
Json::Value frames = root.get(gFrameKey, 0);
assert(frames.isArray());
int num_frames = frames.size();
int data_size = 0;
if (num_frames > 0)
{
int idx0 = 0;
Json::Value frame_json = frames.get(idx0, 0);
data_size = frame_json.size();
mFrames.resize(num_frames, data_size);
}
for (int f = 0; f < num_frames; ++f)
{
Eigen::VectorXd curr_frame;
succ = ParseFrameJson(frames.get(f, 0), curr_frame);
if (succ)
{
assert(mFrames.cols() == curr_frame.size());
mFrames.row(f) = curr_frame;
}
else
{
mFrames.resize(0, 0);
break;
}
}
}
return succ;
}
示例15: FromJson
void OrthancPeerParameters::FromJson(const Json::Value& peer)
{
if (!peer.isArray() ||
(peer.size() != 1 && peer.size() != 3))
{
throw OrthancException(ErrorCode_BadFileFormat);
}
std::string url;
try
{
url = peer.get(0u, "").asString();
if (peer.size() == 1)
{
SetUsername("");
SetPassword("");
}
else if (peer.size() == 3)
{
SetUsername(peer.get(1u, "").asString());
SetPassword(peer.get(2u, "").asString());
}
else
{
throw OrthancException(ErrorCode_BadFileFormat);
}
}
catch (...)
{
throw OrthancException(ErrorCode_BadFileFormat);
}
if (url.size() != 0 && url[url.size() - 1] != '/')
{
url += '/';
}
SetUrl(url);
}