本文整理汇总了C++中JsonObject类的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject类的具体用法?C++ JsonObject怎么用?C++ JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_effect_type
void load_effect_type(JsonObject &jo)
{
effect_type new_etype;
new_etype.id = jo.get_string("id");
new_etype.name = jo.get_string("name", "");
new_etype.desc = jo.get_string("desc", "");
new_etype.apply_message = jo.get_string("apply_message", "");
new_etype.remove_message = jo.get_string("remove_message", "");
new_etype.apply_memorial_log = jo.get_string("apply_memorial_log", "");
new_etype.remove_memorial_log = jo.get_string("remove_memorial_log", "");
effect_types[new_etype.id] = new_etype;
}
示例2: load
bool map_deconstruct_info::load(JsonObject &jsobj, std::string member, bool isfurniture)
{
if (!jsobj.has_object(member)) {
return false;
}
JsonObject j = jsobj.get_object(member);
furn_set = j.get_string("furn_set", "");
if (!isfurniture) {
ter_set = j.get_string("ter_set");
}
can_do = true;
load_map_bash_item_drop_list(j.get_array("items"), items);
return true;
}
示例3: load
bool map_deconstruct_info::load(JsonObject &jsobj, std::string member, bool isfurniture)
{
if (!jsobj.has_object(member)) {
return false;
}
JsonObject j = jsobj.get_object(member);
furn_set = j.get_string("furn_set", "");
if (!isfurniture) {
ter_set = j.get_string( "ter_set" );
}
can_do = true;
JsonIn& stream = *j.get_raw( "items" );
drop_group = item_group::load_item_group( stream, "collection" );
return true;
}
示例4: while
void sfx::load_playlist( JsonObject &jsobj )
{
if( !sound_init_success ) {
return;
}
JsonArray jarr = jsobj.get_array( "playlists" );
while( jarr.has_more() ) {
JsonObject playlist = jarr.next_object();
const std::string playlist_id = playlist.get_string( "id" );
music_playlist playlist_to_load;
playlist_to_load.shuffle = playlist.get_bool( "shuffle", false );
JsonArray files = playlist.get_array( "files" );
while( files.has_more() ) {
JsonObject entry = files.next_object();
const music_playlist::entry e{ entry.get_string( "file" ), entry.get_int( "volume" ) };
playlist_to_load.entries.push_back( e );
}
playlists[playlist_id] = std::move( playlist_to_load );
}
}
示例5: setData
void Comment::setData(const JsonObject &data, bool signalChange)
{
QString id = JSON_GET_STRING(data.value(COMMENT_ID_KEY));
QString name = JSON_GET_STRING(data.value(COMMENT_NAME_KEY));
QString url = JSON_GET_STRING(data.value(COMMENT_URL_KEY));
QString dateString = JSON_GET_STRING(data.value(COMMENT_DATE_KEY));
QDateTime date = QDateTime::fromString(dateString, DATE_TIME_FORMAT);
QString content = JSON_GET_STRING(data.value(COMMENT_CONTENT_KEY));
QString parent = JSON_GET_STRING(data.value(COMMENT_PARENT_KEY));
if (m_id != id) {
m_id = id;
if (signalChange) {
emit idChanged();
}
}
if (m_name != name) {
m_name = name;
if (signalChange) {
emit nameChanged();
}
}
if (m_url != url) {
m_url = url;
if (signalChange) {
emit urlChanged();
}
}
if (m_date != date) {
m_date = date;
if (signalChange) {
emit dateChanged();
}
}
if (m_content != content) {
m_content = content;
if (signalChange) {
emit contentChanged();
}
}
if (m_parent != parent) {
m_parent = parent;
if (signalChange) {
emit parentChanged();
}
}
}
示例6: visitFunctionStatement
void visitFunctionStatement(FunctionStatement *node) override {
JsonObject *obj = new (pool_) JsonObject();
obj->add(atom_name_, toJson(node->name()));
startDoc(obj, "function", node->name(), node->loc());
if (node->token() == TOK_FORWARD)
obj->add(atom_kind_, toJson("forward"));
else if (node->token() == TOK_NATIVE)
obj->add(atom_kind_, toJson("native"));
else
obj->add(atom_kind_, toJson("stock"));
obj->add(atom_returnType_, toJson(node->signature()->returnType()));
obj->add(atom_parameters_, toJson(node->signature()->parameters()));
functions_->add(obj);
}
示例7: 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;
}
示例8: setOffsetTime
int cRooms::setOffsetTime( JsonObject& root )
{
int fail=0;
int succes=0;
if(root.containsKey("Rt")) {
if(root["Rt"].is<JsonArray&>()){
JsonArray& times = root["Rt"];
if (times.size()==(nSetTypes*nRoomTypes*nDayTypes*nSwitch))
{
for(int iSet = 0; iSet<nSetTypes; iSet++)
{
for(int iRoomType = 0; iRoomType<nRoomTypes; iRoomType++) // Iterate over all Roomtypes (Living, sleeping, hallway, side)
{
for(int iDayType = 0; iDayType<nDayTypes; iDayType++)
{
for(int iSwitch = 0; iSwitch<nSwitch; iSwitch++)
{
int idx = iSwitch+iDayType*(nSwitch)+iRoomType*(nDayTypes)*(nSwitch)+iSet*(nRoomTypes)*(nDayTypes)*(nSwitch);
if (times[idx].is<long>()) {
unsigned long oldTime = TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].time.totalseconds();
unsigned long newTime = times[idx].as<long>();
if((newTime>=0)&&(24*60*60-newTime>=0)&&(newTime!=oldTime)){
TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].time.set(newTime);
succes=1;
}
}
else fail=1;
}
}
}
}
}
}
}
return (!fail)&&(succes);
}
示例9: visitTypesetDecl
void visitTypesetDecl(TypesetDecl *decl) override {
JsonObject *obj = new (pool_) JsonObject();
obj->add(atom_name_, toJson(decl->name()));
startDoc(obj, "typeset", decl->name(), decl->loc());
JsonList *list = new (pool_) JsonList();
for (size_t i = 0; i < decl->types()->length(); i++) {
const TypesetDecl::Entry &entry = decl->types()->at(i);
JsonObject *te = new (pool_) JsonObject();
te->add(atom_type_, toJson(entry.te));
unsigned start, end;
if (comments_.findCommentFor(entry.loc, &start, &end)) {
te->add(atom_doc_start_, new (pool_) JsonInt(start));
te->add(atom_doc_end_, new (pool_) JsonInt(end));
}
list->add(te);
}
obj->add(cc_.add("types"), list);
typesets_->add(obj);
}
示例10: setOffsetTemp
int cRooms::setOffsetTemp( JsonObject& root )
{
int fail=0;
int succes=0;
if(root.containsKey("RTo")) {
if(root["RTo"].is<JsonArray&>()){
JsonArray& temps = root["RTo"];
if (temps.size()==(nSetTypes*nRoomTypes*nDayTypes*nSwitch))
{
for(int iSet = 0; iSet<nSetTypes; iSet++) // Normal
{
for(int iRoomType = 0; iRoomType<nRoomTypes; iRoomType++) // (Living, sleeping, hallway, bath, side)
{
for(int iDayType = 0; iDayType<nDayTypes; iDayType++) // Weekend, Workday
{
for(int iSwitch = 0; iSwitch<nSwitch; iSwitch++) // 4 switch times
{
// Last iteration
int idx = iSwitch+iDayType*(nSwitch)+iRoomType*(nDayTypes)*(nSwitch)+iSet*(nRoomTypes)*(nDayTypes)*(nSwitch);
if (temps[idx].is<double>()){
double temp_ = temps[idx].as<double>();
if((temp_>-15.0)&&(temp_<15.0)&&(temp_!=TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].temp)){
TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].temp = temp_;
succes = 1;
}
}
else fail=1;
}
}
}
}
}
}
}
return ((!fail)&&(succes));
}
示例11: load
void furn_t::load( JsonObject &jo, const std::string &src )
{
map_data_common_t::load( jo, src );
mandatory( jo, was_loaded, "name", name_ );
mandatory( jo, was_loaded, "move_cost_mod", movecost );
mandatory( jo, was_loaded, "required_str", move_str_req );
optional( jo, was_loaded, "max_volume", max_volume, legacy_volume_reader, DEFAULT_MAX_VOLUME_IN_SQUARE );
optional( jo, was_loaded, "crafting_pseudo_item", crafting_pseudo_item, "" );
optional( jo, was_loaded, "deployed_item", deployed_item );
load_symbol( jo );
transparent = false;
for( auto & flag : jo.get_string_array( "flags" ) ) {
set_flag( flag );
}
optional( jo, was_loaded, "open", open, string_id_reader<furn_t> {}, furn_str_id::NULL_ID() );
optional( jo, was_loaded, "close", close, string_id_reader<furn_t> {}, furn_str_id::NULL_ID() );
bash.load( jo, "bash", true );
deconstruct.load( jo, "deconstruct", true );
}
示例12: load_distribution
distribution load_distribution( JsonObject &jo, const std::string &name )
{
if( !jo.has_member( name ) ) {
return distribution();
}
if( jo.has_float( name ) ) {
return distribution::constant( jo.get_float( name ) );
}
if( jo.has_object( name ) ) {
JsonObject obj = jo.get_object( name );
return load_distribution( obj );
}
jo.throw_error( "Invalid distribution type", name );
return distribution();
}
示例13: fromJson
bool DriveCommand::fromJson(JsonObject& cmd) {
if(!cmd.containsKey("type")) return false;
const char* type = cmd["type"];
if(strcmp(type, "SET_HEADING") == 0) {
command = SET_HEADING;
} else if(strcmp(type, "DRIVE") == 0) {
command = DRIVE;
} else {
Serial.print("unrecognized type ");
Serial.println(type);
return false;
}
if(!cmd.containsKey("cid") || !cmd.containsKey("pid") || !cmd.containsKey("duration")) {
return false;
}
cid = cmd["cid"];
pid = cmd["pid"];
duration = cmd["duration"];
if(command == DRIVE) {
if(!cmd.containsKey("speed") || !cmd.containsKey("heading")) return false;
payload.drive.speed = cmd["speed"];
payload.drive.heading = cmd["heading"];
return true;
} else if(command == SET_HEADING) {
if(!cmd.containsKey("heading")) return false;
payload.heading.heading = cmd["heading"];
return true;
} else {
return false;
}
}
示例14: load_bionic
void load_bionic(JsonObject &jsobj)
{
std::string id = jsobj.get_string("id");
std::string name = _(jsobj.get_string("name").c_str());
std::string description = _(jsobj.get_string("description").c_str());
int cost = jsobj.get_int("cost", 0);
int time = jsobj.get_int("time", 0);
bool faulty = jsobj.get_bool("faulty", false);
bool power_source = jsobj.get_bool("power_source", false);
bool active = jsobj.get_bool("active", false);
if (faulty) {
faulty_bionics.push_back(id);
}
if (power_source) {
power_source_bionics.push_back(id);
}
if (!active) {
unpowered_bionics.push_back(id);
}
bionics[id] = new bionic_data(name, power_source, active, cost, time, description, faulty);
}
示例15: load
bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) {
if( jsobj.has_object(member) ) {
JsonObject j = jsobj.get_object(member);
if ( jsonint(j, "num_tests", num_tests ) == false ) {
if ( jsonint(j, "str_min", str_min ) && jsonint(j, "str_max", str_max ) ) {
num_tests = 1;
}
} else if ( num_tests > 0 ) {
str_min = j.get_int("str_min");
str_max = j.get_int("str_max");
}
jsonint(j, "str_min_blocked", str_min_blocked );
jsonint(j, "str_max_blocked", str_max_blocked );
jsonint(j, "str_min_roll", str_min_roll );
jsonint(j, "explosive", explosive );
jsonint(j, "chance", chance );
jsonstring(j, "sound", sound );
jsonstring(j, "sound_fail", sound_fail );
jsonstring(j, "furn_set", furn_set );
if ( jsonstring(j, "ter_set", ter_set ) == false && isfurniture == false ) {
ter_set = "t_rubble";
debugmsg("terrain[\"%s\"].bash.ter_set is not set!",jsobj.get_string("id").c_str() );
}
if ( j.has_array("items") ) {
load_map_bash_item_drop_list(j.get_array("items"), items);
}
//debugmsg("%d/%d %s %s/%s %d",str_min,str_max, ter_set.c_str(), sound.c_str(), sound_fail.c_str(), items.size() );
return true;
} else {
return false;
}
}