本文整理汇总了C++中json::Value::asBool方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::asBool方法的具体用法?C++ Value::asBool怎么用?C++ Value::asBool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::asBool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Deserialize
bool Deserialize ( const Json::Value& json_val, bool& obj_val )
{
/**
* Warning: the default type may be int, even you Serialize a bool value
*/
if ( json_val.isBool () )
{
obj_val = json_val.asBool ();
return true;
}
else if ( json_val.isInt () )
{
int tmp = json_val.asInt ();
if ( ! tmp )
{
obj_val = false;
}
else
{
obj_val = true;
}
return true;
}
return false;
}
示例2: jsonValueToVariant
FB::variant jsonValueToVariant( Json::Value root )
{
Json::Value def;
if (root.isString())
return root.asString();
else if (root.isBool())
return root.asBool();
else if (root.isDouble())
return root.asDouble();
else if (root.isInt())
return root.asInt();
else if (root.isUInt())
return root.asUInt();
else if (root.isNull())
return FB::FBNull();
else if (root.isArray()) {
FB::VariantList outList;
for (size_t i = 0; i < root.size(); ++i) {
outList.push_back(jsonValueToVariant(root.get(i, def)));
}
return outList;
} else if (root.isObject()) {
Json::Value::Members members = root.getMemberNames();
FB::VariantMap outMap;
for (Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)
{
outMap[*it] = jsonValueToVariant(root.get(*it, def));
}
return outMap;
} else {
return FB::FBVoid();
}
}
示例3: ToBool
bool JsonHelper::ToBool( const Json::Value& value, bool defaultResult )
{
if ( value.isBool() )
{
return value.asBool();
}
if ( value.isInt() )
{
return (bool)value.asInt();
}
if ( value.isDouble() )
{
return (bool)value.asDouble();
}
if ( value.isUInt() )
{
return (bool)value.asUInt();
}
if ( value.isString() )
{
const std::string& str = value.asString();
return ( str == "true" || str == "1" );
}
return defaultResult;
}
示例4: GetVal
void GetVal(Json::Value &config, bool* setting)
{
if (config.isNull())
return;
*setting = config.asBool();
}
示例5: toAny
AnyValue JsonSerializer::toAny(const Json::Value & val)
{
std::vector<AnyValue> arr;
Bundle b;
switch (val.type())
{
case Json::ValueType::arrayValue:
for (auto e : val) arr.push_back(this->toAny(e));
return arr;
case Json::ValueType::booleanValue:
return val.asBool();
case Json::ValueType::intValue:
return (int64_t)val.asInt64();
case Json::ValueType::nullValue:
return nullptr;
case Json::ValueType::objectValue:
for (Json::ValueConstIterator it = val.begin(); it != val.end(); it++)
{
std::string name = it.name();
b.set(name, this->toAny(*it));
}
return b;
case Json::ValueType::realValue:
return val.asDouble();
case Json::ValueType::stringValue:
return val.asString();
case Json::ValueType::uintValue:
return (uint64_t)val.asUInt64();
}
return AnyValue();
}
示例6: if
Expectations::Expectations(Json::Value jsonElement) {
if (jsonElement.empty()) {
fIgnoreFailure = kDefaultIgnoreFailure;
} else {
Json::Value ignoreFailure = jsonElement[kJsonKey_ExpectedResults_IgnoreFailure];
if (ignoreFailure.isNull()) {
fIgnoreFailure = kDefaultIgnoreFailure;
} else if (!ignoreFailure.isBool()) {
SkDebugf("found non-boolean json value for key '%s' in element '%s'\n",
kJsonKey_ExpectedResults_IgnoreFailure,
jsonElement.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
fIgnoreFailure = kDefaultIgnoreFailure;
} else {
fIgnoreFailure = ignoreFailure.asBool();
}
Json::Value allowedDigests = jsonElement[kJsonKey_ExpectedResults_AllowedDigests];
if (allowedDigests.isNull()) {
// ok, we'll just assume there aren't any AllowedDigests to compare against
} else if (!allowedDigests.isArray()) {
SkDebugf("found non-array json value for key '%s' in element '%s'\n",
kJsonKey_ExpectedResults_AllowedDigests,
jsonElement.toStyledString().c_str());
DEBUGFAIL_SEE_STDERR;
} else {
for (Json::ArrayIndex i=0; i<allowedDigests.size(); i++) {
fAllowedResultDigests.push_back(GmResultDigest(allowedDigests[i]));
}
}
}
}
示例7: set
void Object::set (std::string const& k, Json::Value const& v)
{
auto t = v.type();
switch (t)
{
case Json::nullValue:
return set (k, nullptr);
case Json::intValue:
return set (k, v.asInt());
case Json::uintValue:
return set (k, v.asUInt());
case Json::realValue:
return set (k, v.asDouble());
case Json::stringValue:
return set (k, v.asString());
case Json::booleanValue:
return set (k, v.asBool());
case Json::objectValue:
{
auto object = setObject (k);
copyFrom (object, v);
return;
}
case Json::arrayValue:
{
auto array = setArray (k);
for (auto& item: v)
array.append (item);
return;
}
}
assert (false); // Can't get here.
}
示例8: add
static void add(
MetadataNode& parent,
const std::string& name,
const Json::Value& node
)
{
if (node.isNull()) { parent.add(name, ""); }
else if (node.isBool()) { parent.add(name, node.asBool()); }
else if (node.isInt()) { parent.add(name, node.asInt64()); }
else if (node.isUInt()) { parent.add(name, node.asUInt64()); }
else if (node.isDouble()) { parent.add(name, node.asDouble()); }
else if (node.isString()) { parent.add(name, node.asString()); }
else if (node.isObject())
{
MetadataNode object = parent.add(name);
for (const std::string& name: node.getMemberNames())
{
add(object, name, node[name]);
}
}
else if (node.isArray())
{
for (const Json::Value& item: node)
{
add(parent, name, item);
}
}
}
示例9: GetBoolFromJsonValue
bool Utils::GetBoolFromJsonValue(Json::Value &value) {
// some json responses have string bools formated as string literals
if (value.isString()) {
return value.asString().compare("true") == 0;
} else {
return value.asBool();
}
}
示例10: switch
static void
printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
switch ( value.type() )
{
case Json::nullValue:
fprintf( fout, "%s=null\n", path.c_str() );
break;
case Json::intValue:
fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestInt() ).c_str() );
break;
case Json::uintValue:
fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestUInt() ).c_str() );
break;
case Json::realValue:
fprintf( fout, "%s=%s\n", path.c_str(), normalizeFloatingPointStr(value.asDouble()).c_str() );
break;
case Json::stringValue:
fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
break;
case Json::booleanValue:
fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
break;
case Json::arrayValue:
{
fprintf( fout, "%s=[]\n", path.c_str() );
int size = value.size();
for ( int index =0; index < size; ++index )
{
static char buffer[16];
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
sprintf_s( buffer, sizeof(buffer), "[%d]", index );
#else
snprintf( buffer, sizeof(buffer), "[%d]", index );
#endif
printValueTree( fout, value[index], path + buffer );
}
}
break;
case Json::objectValue:
{
fprintf( fout, "%s={}\n", path.c_str() );
Json::Value::Members members( value.getMemberNames() );
std::sort( members.begin(), members.end() );
std::string suffix = *(path.end()-1) == '.' ? "" : ".";
for ( Json::Value::Members::iterator it = members.begin();
it != members.end();
++it )
{
const std::string &name = *it;
printValueTree( fout, value[name], path + suffix + name );
}
}
break;
default:
break;
}
}
示例11: init
void JsonTree::init( const string &key, const Json::Value &value, bool setType, NodeType nodeType, ValueType valueType )
{
mKey = key;
mNodeType = nodeType;
mParent = 0;
mValue = "";
mValueType = valueType;
if( ! value.isNull() && ( value.isArray() || value.isObject() ) ) {
if( value.isArray() ) {
mNodeType = NODE_ARRAY;
for ( uint32_t i = 0; i < value.size(); i++ ) {
pushBack( JsonTree( "", value[ i ] ) );
}
}
else if( value.isObject() ) {
mNodeType = NODE_OBJECT;
Json::Value::Members members = value.getMemberNames();
for( Json::Value::Members::const_iterator memberIt = members.begin(); memberIt != members.end(); ++memberIt ) {
string key = *memberIt;
pushBack( JsonTree( key, value[ key ] ) );
}
}
}
else {
if( value.isBool() ) {
mValue = toString( value.asBool() );
if( setType ) {
mValueType = VALUE_BOOL;
}
}
else if ( value.isDouble() ) {
mValue = toString( value.asDouble() );
if ( setType ) {
mValueType = VALUE_DOUBLE;
}
}
else if ( value.isInt() ) {
mValue = toString( value.asInt() );
if ( setType ) {
mValueType = VALUE_INT;
}
}
else if ( value.isString() ) {
mValue = toString( value.asString() );
if ( setType ) {
mValueType = VALUE_STRING;
}
}
else if ( value.isUInt() ) {
mValue = toString( value.asUInt() );
if ( setType ) {
mValueType = VALUE_UINT;
}
}
}
}
示例12: isSyncing
bool BlockChain::isSyncing()
{
Json::Value result = _provider.request("eth_isSyncing");
if(result.isBool())
{
return result.asBool();
}
return true;
}
示例13:
bool ConfigFile::is_data_shared_1(std::string package) {
const Json::Value sharedata =
m_root[CONF_PACKAGES][package][CONF_SHARE_DATA];
if (!sharedata.isNull() && !sharedata.isBool()) {
return sharedata.asBool();
}
return false;
}
示例14: GetBool
bool GetBool(const Json::Value& value, bool* out) {
if (value.isNull()) {
return false;
}
if (!value.isBool()) {
return false;
}
*out = value.asBool();
return true;
}
示例15: GetJsonInt
int GetJsonInt(const Json::Value& _jsValue)
{
if ( _jsValue.type() == Json::intValue)
return _jsValue.asInt();
else if (_jsValue.type() == Json::stringValue)
return atoi(_jsValue.asCString());
else if (_jsValue.isBool())
return (int)_jsValue.asBool();
return 0;
}