当我问rapidjson::Value使用GetType()方法的类型时,它只返回下面的类型:
//! 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
};
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,有没有这样的kIntType也不是kDoubleType(甚至kUintType,kInt64Type中).因此,我不能得到实际值rapidjson::Value.
例如:
if (value.GetType() == rapidjson::kNumberType)
{
double v = value.GetDouble() // this?
unsigned long v = value.GetUInt64() // or this??
int v = value.GetInt() // or this?
}
Run Code Online (Sandbox Code Playgroud)
反正是否有区分实际的数字类型?
谢谢.
有:
bool Value::IsInt() constbool Value::IsUint() constbool Value::IsInt64() constbool Value::IsUint64() constbool Value::IsDouble() const请注意,1-4不是彼此独有的.例如,该值123将返回1-4,true但将返回5 false.GetDouble()当IsNumber()或者1-5 时,调用总是正常true,但是当值实际上是64位(无符号)整数时,可能会出现精度损失.
http://miloyip.github.io/rapidjson/md_doc_tutorial.html#QueryNumber