When I ask type of rapidjson::Value
using GetType()
method, it returns only belows Type:
//! Type of JSON value
enum Type {
kNullType = 0, //!< null
kFalseType = 1, //!< false
kTrueType = 2, //!< true
kObjectType = 3, //!< object
kArrayType = 4, //!< array
kStringType = 5, //!< string
kNumberType = 6 //!< number
};
As you can see, there are no such kIntType
nor kDoubleType
(even kUintType
, kInt64Type
) Therefore, I can't get actual value of rapidjson::Value
.
For example:
if (value.GetType() == rapidjson::kNumberType)
{
double v = value.GetDouble() // this?
unsigned long v = value.GetUInt64() // or this??
int v = value.GetInt() // or this?
}
Is there anyway to distinguish actual numeric type?
Thanks.
There are:
bool Value::IsInt() const
bool Value::IsUint() const
bool Value::IsInt64() const
bool Value::IsUint64() const
bool Value::IsDouble() const
Note that, 1-4 are not exclusive to each other. For example, the value 123
will make 1-4 return true
but 5 will return false
. And calling GetDouble()
is always OK when IsNumber()
or 1-5 is true
, though precision loss is possible when the value is actually a 64-bit (unsigned) integer.
http://miloyip.github.io/rapidjson/md_doc_tutorial.html#QueryNumber
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With