本文整理汇总了C++中JsonIn::error方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonIn::error方法的具体用法?C++ JsonIn::error怎么用?C++ JsonIn::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonIn
的用法示例。
在下文中一共展示了JsonIn::error方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_all_from_json
void DynamicDataLoader::load_all_from_json(JsonIn &jsin)
{
char ch;
jsin.eat_whitespace();
// examine first non-whitespace char
ch = jsin.peek();
if (ch == '{') {
// find type and dispatch single object
JsonObject jo = jsin.get_object();
load_object(jo);
jo.finish();
// if there's anything else in the file, it's an error.
jsin.eat_whitespace();
if (jsin.good()) {
jsin.error( string_format( "expected single-object file but found '%c'", jsin.peek() ) );
}
} else if (ch == '[') {
jsin.start_array();
// find type and dispatch each object until array close
while (!jsin.end_array()) {
jsin.eat_whitespace();
ch = jsin.peek();
if (ch != '{') {
jsin.error( string_format( "expected array of objects but found '%c', not '{'", ch ) );
}
JsonObject jo = jsin.get_object();
load_object(jo);
jo.finish();
}
} else {
// not an object or an array?
jsin.error( string_format( "expected object or array, but found '%c'", ch ) );
}
}
示例2: load_all_from_json
void DynamicDataLoader::load_all_from_json( JsonIn &jsin, const std::string &src, loading_ui &,
const std::string &base_path, const std::string &full_path )
{
if( jsin.test_object() ) {
// find type and dispatch single object
JsonObject jo = jsin.get_object();
load_object( jo, src, base_path, full_path );
jo.finish();
// if there's anything else in the file, it's an error.
jsin.eat_whitespace();
if( jsin.good() ) {
jsin.error( string_format( "expected single-object file but found '%c'", jsin.peek() ) );
}
} else if( jsin.test_array() ) {
jsin.start_array();
// find type and dispatch each object until array close
while( !jsin.end_array() ) {
JsonObject jo = jsin.get_object();
load_object( jo, src, base_path, full_path );
jo.finish();
}
} else {
// not an object or an array?
jsin.error( "expected object or array" );
}
}
示例3: load_item_group
Group_tag item_group::load_item_group( JsonIn& stream, const std::string& default_subtype )
{
if( stream.test_string() ) {
return stream.get_string();
} else if( stream.test_object() ) {
const Group_tag group = get_unique_group_id();
JsonObject jo = stream.get_object();
const std::string subtype = jo.get_string( "subtype", default_subtype );
item_controller->load_item_group( jo, group, subtype );
return group;
} else if( stream.test_array() ) {
const Group_tag group = get_unique_group_id();
JsonArray jarr = stream.get_array();
// load_item_group needs a bool, invalid subtypes are unexpected and most likely errors
// from the caller of this function.
if( default_subtype != "collection" && default_subtype != "distribution" ) {
debugmsg( "invalid subtype for item group: %s", default_subtype.c_str() );
}
item_controller->load_item_group( jarr, group, default_subtype == "collection" );
return group;
} else {
stream.error( "invalid item group, must be string (group id) or object/array (the group data)" );
// stream.error always throws, this is here to prevent a warning
return Group_tag{};
}
}
示例4: load_trait_group
Trait_group_tag trait_group::load_trait_group( JsonIn &stream, const std::string &default_subtype )
{
if( stream.test_string() ) {
return Trait_group_tag( stream.get_string() );
} else if( stream.test_object() ) {
const Trait_group_tag group = get_unique_trait_group_id();
JsonObject jo = stream.get_object();
const std::string subtype = jo.get_string( "subtype", default_subtype );
mutation_branch::load_trait_group( jo, group, subtype );
return group;
} else if( stream.test_array() ) {
const Trait_group_tag group = get_unique_trait_group_id();
JsonArray jarr = stream.get_array();
if( default_subtype != "collection" && default_subtype != "distribution" ) {
jarr.throw_error( "invalid subtype for trait group" );
}
mutation_branch::load_trait_group( jarr, group, default_subtype == "collection" );
return group;
} else {
stream.error( "invalid trait group, must be string (group id) or object/array (the group data)" );
return Trait_group_tag{};
}
}
示例5: load_all_from_json
void load_all_from_json(JsonIn &jsin)
{
char ch;
std::string type = "";
jsin.eat_whitespace();
// examine first non-whitespace char
ch = jsin.peek();
if (ch == '{') {
// find type and dispatch single object
JsonObject jo = jsin.get_object();
load_object(jo);
jo.finish();
// if there's anything else in the file, it's an error.
jsin.eat_whitespace();
if (jsin.good()) {
std::stringstream err;
err << "expected single-object file but found '";
err << jsin.peek() << "'";
jsin.error( err.str() );
}
} else if (ch == '[') {
jsin.start_array();
// find type and dispatch each object until array close
while (!jsin.end_array()) {
jsin.eat_whitespace();
ch = jsin.peek();
if (ch != '{') {
std::stringstream err;
err << "expected array of objects but found '";
err << ch << "', not '{'";
jsin.error( err.str() );
}
JsonObject jo = jsin.get_object();
load_object(jo);
jo.finish();
}
} else {
// not an object or an array?
std::stringstream err;
err << "expected object or array, but found '" << ch << "'";
jsin.error( err.str() );
}
}
示例6: string_to_symbol
long string_to_symbol( JsonIn &js )
{
const std::string s = js.get_string();
if( s == "LINE_XOXO" ) {
return LINE_XOXO;
} else if( s == "LINE_OXOX" ) {
return LINE_OXOX;
} else if( s.length() != 1 ) {
js.error( "Symbol string must be exactly 1 character long." );
}
return s[0];
}
示例7: positions
/* class JsonObject
* represents a JSON object,
* providing access to the underlying data.
*/
JsonObject::JsonObject(JsonIn &j) : positions()
{
jsin = &j;
start = jsin->tell();
// cache the position of the value for each member
jsin->start_object();
while (!jsin->end_object()) {
std::string n = jsin->get_member_name();
int p = jsin->tell();
if (n != "//" && n != "comment" && positions.count(n) > 0) {
// members with name "//" or "comment" are used for comments and
// should be ignored anyway.
j.error("duplicate entry in json object");
}
positions[n] = p;
jsin->skip_value();
}
end = jsin->tell();
final_separator = jsin->get_ate_separator();
}