我可以区分 rapidjson 中的 Integer 和 Double 类型吗

Can I distinguish Integer and Double type in rapidjson

当我使用 GetType() 方法询问 rapidjson::Value 的类型时,它 returns 仅低于类型:

//! 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
};

如您所见,没有 kIntTypekDoubleType(甚至 kUintTypekInt64Type)因此,我无法获得 [的实际值=12=].

例如:

if (value.GetType() == rapidjson::kNumberType)
{
    double v = value.GetDouble()        // this?
    unsigned long v = value.GetUInt64() // or this??
    int v = value.GetInt()              // or this?
}

有没有办法区分实际的数字类型?

谢谢。

有:

  1. bool Value::IsInt() const
  2. bool Value::IsUint() const
  3. bool Value::IsInt64() const
  4. bool Value::IsUint64() const
  5. bool Value::IsDouble() const

请注意,1-4 并不互斥。例如,值 123 将使 1-4 return true 但 5 将 return false。当 IsNumber() 或 1-5 为 true 时调用 GetDouble() 总是可以的,尽管当该值实际上是 64 位(无符号)整数时可能会丢失精度。

http://miloyip.github.io/rapidjson/md_doc_tutorial.html#QueryNumber