本文整理汇总了C++中json::Value::asInt64方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::asInt64方法的具体用法?C++ Value::asInt64怎么用?C++ Value::asInt64使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::asInt64方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例3: 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();
}
示例4: 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);
}
}
}
示例5: Deserialize
bool Deserialize ( const Json::Value& json_val, json_lib::int64& obj_val )
{
if ( json_val.isIntegral () )
{
obj_val = json_val.asInt64 ();
return true;
}
return false;
}
示例6: deserialize
bool deserialize(const Json::Value& node, int64_t& val)
{
if (node.empty())
{
std::cout << "Node is empty." << std::endl;
return false;
}
if (!node.isNumeric())
{
std::cout << "Node data type is not numeric." << std::endl;
return false;
}
val = node.asInt64();
return true;
}
示例7: fromJSON
template<> ZEROBUF_INL int64_t fromJSON( const Json::Value& json )
{ return json.asInt64(); }
示例8:
int64_t jsonNodeAs<int64_t>(const Json::Value& node) {
if (node.isNull()) {
return 0;
}
return node.asInt64();
}
示例9: ToPbSingle
int ToPbSingle(const Json::Value &value, const FieldDescriptor *pFieldDescriptor, Message &message, map<string, string>& key_map)
{
if (!check_type(value.type(), pFieldDescriptor->cpp_type()))
{
return 1;
}
const Reflection *pReflection = message.GetReflection();
EnumDescriptor *pEnumDes = NULL;
EnumValueDescriptor *pEnumValueDes = NULL;
int ret = 0;
switch(pFieldDescriptor->cpp_type())
{
case FieldDescriptor::CPPTYPE_INT32:
{
pReflection->SetInt32(&message, pFieldDescriptor, value.asInt());
break;
}
case FieldDescriptor::CPPTYPE_UINT32:
{
pReflection->SetUInt32(&message, pFieldDescriptor, value.asUInt());
break;
}
case FieldDescriptor::CPPTYPE_INT64:
{
pReflection->SetInt64(&message, pFieldDescriptor, value.asInt64());
break;
}
case FieldDescriptor::CPPTYPE_UINT64:
{
pReflection->SetUInt64(&message, pFieldDescriptor, value.asUInt64());
break;
}
case FieldDescriptor::CPPTYPE_STRING:
{
pReflection->SetString(&message, pFieldDescriptor, value.asString());
break;
}
case FieldDescriptor::CPPTYPE_BOOL:
{
pReflection->SetBool(&message, pFieldDescriptor, value.asBool());
break;
}
case FieldDescriptor::CPPTYPE_DOUBLE:
{
pReflection->SetDouble(&message, pFieldDescriptor, value.asDouble());
break;
}
case FieldDescriptor::CPPTYPE_FLOAT:
{
pReflection->SetFloat(&message, pFieldDescriptor, value.asFloat());
break;
}
case FieldDescriptor::CPPTYPE_ENUM:
{
if ((pEnumDes = (EnumDescriptor *)pFieldDescriptor->enum_type()) == NULL)
{
return 1;
}
if ((pEnumValueDes = (EnumValueDescriptor *)pEnumDes->FindValueByNumber(value.asInt())) == NULL)
{
return 1;
}
pReflection->SetEnum(&message, pFieldDescriptor, pEnumValueDes);
break;
}
case FieldDescriptor::CPPTYPE_MESSAGE:
{
Message *pmessage = pReflection->MutableMessage(&message, pFieldDescriptor);
if (key_map.size() == 0)
{
ret = ToPb(*pmessage, value);
}
else
{
ret = ToPbMap(*pmessage, value, key_map);
}
break;
}
default:
{
ret = 1;
break;
}
}
return ret;
}