本文整理汇总了C++中json::Value::isInt方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::isInt方法的具体用法?C++ Value::isInt怎么用?C++ Value::isInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::isInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: jsonToValues
Values Factory::jsonToValues(const Json::Value& values)
{
Values outValues;
if (values.isInt())
outValues.emplace_back(values.asInt());
else if (values.isDouble())
outValues.emplace_back(values.asFloat());
else if (values.isArray())
for (const auto& v : values)
{
if (v.isInt())
outValues.emplace_back(v.asInt());
else if (v.isDouble())
outValues.emplace_back(v.asFloat());
else if (v.isArray())
outValues.emplace_back(jsonToValues(v));
else
outValues.emplace_back(v.asString());
}
else
outValues.emplace_back(values.asString());
return outValues;
}
示例2: 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;
}
示例3: generateKey
/**
* Expected input:
* {
* alg: "aes",
* keySize : an int - 128/192/256
* }
*
* Output:
* {
* key: generated key data
* }
*/
Json::Value AES::generateKey(const std::string & algorithm,
Json::Value & args) {
size_t keySize = 128;
if (args.isMember("keySize")) {
Json::Value keySizeV = args["keySize"];
if (!keySizeV.isInt()) {
throw std::string("keySize must be an int");
}
keySize = keySizeV.asInt();
switch (keySize) {
case 128:
case 192:
case 256:
// awesome!
break;
default:
throw errorMessage("Not a valid key size: ", keySize);
}
}
AESParams params(*this, SB_AES_CBC, SB_AES_128_BLOCK_BITS, true);
DataTracker dt;
AESKey key(params, keySize);
key.get(dt);
Json::Value keyData = toJson(dt.data, dt.dataLen);
Json::Value toReturn;
toReturn["key"] = keyData;
return toReturn;
}
示例4: natural
// Read a natural
Natural natural(
Optizelle::Messaging const & msg,
Json::Value const & json,
std::string const & name
) {
// Set the error message
std::string const err_msg = "Invalid JSON parameter: "
+ name + " contains an invalid natural.";
// As long as we have an unsigned integer, grab it
if(json.isUInt())
return Natural(Json::Value::UInt64(json.asUInt64()));
// If we have an integer, grab it if it's positive
else if(json.isInt()) {
Integer val(json.asInt64());
if(val>=0)
return Natural(val);
else
msg.error(err_msg);
// Anything else is an error
} else
msg.error(err_msg);
// We should not hit this point
throw;
}
示例5: 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();
}
}
示例6: 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);
}
}
}
示例7: load_config
bool ConfigFile::load_config() {
std::ifstream file;
file.open(get_config_file());
if (!file) {
LOGE("Config file %s not found", get_config_file().c_str());
return false;
}
Json::Reader reader;
bool success = reader.parse(file, m_root, false);
file.close();
if (!success) {
LOGE("Failed to parse configuration file");
return false;
}
const Json::Value jsonversion = m_root[CONF_VERSION];
if (jsonversion.isInt()) {
m_version = jsonversion.asInt();
} else {
return false;
}
return true;
}
示例8: 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;
}
示例9: readInt
int readInt(std::string key, int def)
{
Json::Value val = root.get(key, def);
if (val.isInt())
return val.asInt();
else
return def;
}
示例10: parseFromJsonToDictionary
/// 从 Json 解析数据到 dictNode 中
static void parseFromJsonToDictionary(const Json::Value & jsonNode, CCDictionary * dictNode)
{
Json::Value::Members members = jsonNode.getMemberNames();
for (Json::Value::Members::iterator beg = members.begin(); beg != members.end(); ++beg)
{
std::string name = *beg;
Json::Value child = jsonNode[name];
if (child.isArray())
{
CCArray * arr = CCArray::create();
parseFromJsonToArray(child, arr);
dictNode->setObject(arr, name);
}
else if (child.isObject())
{
CCDictionary * dict = CCDictionary::create();
parseFromJsonToDictionary(child, dict);
dictNode->setObject(dict, name);
}
else if (child.isString())
{
CCString * str = CCString::createWithFormat("%s", child.asCString());
dictNode->setObject(str, name);
}
else if (child.isInt())
{
CCString * str = CCString::createWithFormat("%d", child.asInt());
dictNode->setObject(str, name);
}
else if (child.isUInt())
{
CCString * str = CCString::createWithFormat("%u", child.asUInt());
dictNode->setObject(str, name);
}
else if (child.isInt64())
{
CCString * str = CCString::createWithFormat("%lld", child.asInt64());
dictNode->setObject(str, name);
}
else if (child.isUInt64())
{
CCString * str = CCString::createWithFormat("%llu", child.asUInt64());
dictNode->setObject(str, name);
}
else if (child.isDouble())
{
CCString * str = CCString::createWithFormat("%f", child.asDouble());
dictNode->setObject(str, name);
}
else if (child.isBool())
{
CCString * str = CCString::createWithFormat("%d", child.asInt());
dictNode->setObject(str, name);
}
}
}
示例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: if
bool QSanProtocol::Utils::tryParse(const Json::Value &arg, double &result) {
if (arg.isDouble())
result = arg.asDouble();
else if (arg.isInt())
result = arg.asInt();
else
return false;
return true;
}
示例13: GetUInt32
bool GetUInt32(const Json::Value& value, uint32_t* out) {
if (value.isNull()) {
return false;
}
if (!(value.isInt() || value.isUInt())) {
return false;
}
*out = value.asUInt();
return true;
}
示例14: GetInt32
bool GetInt32(const Json::Value& value, int32_t* out) {
if (value.isNull()) {
return false;
}
if (!value.isInt()) {
return false;
}
*out = value.asInt();
return true;
}
示例15: GetIntFromJsonValue
int Utils::GetIntFromJsonValue(Json::Value &value, int defaultValue) {
int res = defaultValue;
// some json responses have ints formated as strings
if (value.isString())
res = StringToInt(value.asString());
else if (value.isInt())
res = value.asInt();
return res;
}