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

Jas*_*Heo 2 rapidjson

当我问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)

反正是否有区分实际的数字类型?

谢谢.

Mil*_*Yip 6

有:

  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,true但将返回5 false.GetDouble()IsNumber()或者1-5 时,调用总是正常true,但是当值实际上是64位(无符号)整数时,可能会出现精度损失.

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