当前位置: 首页>>代码示例>>C++>>正文


C++ Value::asBool方法代码示例

本文整理汇总了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;
 }
开发者ID:2014-andy,项目名称:huststore,代码行数:25,代码来源:json_serialization.cpp

示例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();
    }
}
开发者ID:GarysRefererence2014,项目名称:FireBreath,代码行数:33,代码来源:fbjson.cpp

示例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;
 }
开发者ID:Nelar,项目名称:ice_cream_adventure_mobile,代码行数:25,代码来源:JsonHelper.cpp

示例4: GetVal

void GetVal(Json::Value &config, bool* setting)
{
	if (config.isNull())
		return;

	*setting = config.asBool();
}
开发者ID:oSleepY,项目名称:AimTux,代码行数:7,代码来源:settings.cpp

示例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();
		}
开发者ID:Thalhammer,项目名称:EasyCpp,代码行数:31,代码来源:JsonSerializer.cpp

示例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]));
                }
            }
        }
    }
开发者ID:Coolred,项目名称:skia,代码行数:32,代码来源:gm_expectations.cpp

示例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.
}
开发者ID:ripple,项目名称:rippled,代码行数:35,代码来源:Object.cpp

示例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);
         }
     }
 }
开发者ID:chambbj,项目名称:PDAL,代码行数:28,代码来源:RdbReader.cpp

示例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();
    }
}
开发者ID:AlwinEsch,项目名称:pvr.stalker,代码行数:8,代码来源:Utils.cpp

示例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;
   }
}
开发者ID:cdunn2001,项目名称:jsoncpp-old,代码行数:58,代码来源:main.cpp

示例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;
			}
		}
	}
}
开发者ID:RudyOddity,项目名称:Cinder,代码行数:57,代码来源:Json.cpp

示例12: isSyncing

bool BlockChain::isSyncing()
{
    Json::Value result = _provider.request("eth_isSyncing");
    if(result.isBool())
    {
        return result.asBool();
    }
    return true;
}
开发者ID:BitProfile,项目名称:libethrpc,代码行数:9,代码来源:BlockChain.cpp

示例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;
}
开发者ID:Kratos1982,项目名称:DualBootPatcher,代码行数:10,代码来源:configfile.cpp

示例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;
}
开发者ID:bmteam,项目名称:blowmorph,代码行数:10,代码来源:json.cpp

示例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;
}
开发者ID:zjjfhqpl,项目名称:SDLib,代码行数:10,代码来源:CJsonParse.cpp


注:本文中的json::Value::asBool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。