[cpp-restsdk] Update json double/float parse. (#9577)

* [cpp-restsdk] Update json double/float parse.

Fix cpp-restsdk double and float parse.

double.NaN was parsed when server doesn't ensure the floating point value has decimal point in in.

* Update docs & samples.
This commit is contained in:
adameste 2021-05-28 03:58:01 +02:00 committed by GitHub
parent 670c5884b6
commit 73b34ade6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -249,13 +249,13 @@ bool ModelBase::fromJson( const web::json::value& val, bool & outVal )
}
bool ModelBase::fromJson( const web::json::value& val, float & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<float>::quiet_NaN(): static_cast<float>(val.as_double());
return val.is_double();
outVal = (!val.is_double() && !val.is_integer()) ? std::numeric_limits<float>::quiet_NaN(): static_cast<float>(val.as_double());
return val.is_double() || val.is_integer();
}
bool ModelBase::fromJson( const web::json::value& val, double & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
return val.is_double() ;
outVal = (!val.is_double() && !val.is_integer()) ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
return val.is_double() || val.is_integer();
}
bool ModelBase::fromJson( const web::json::value& val, int32_t & outVal )
{

View File

@ -260,13 +260,13 @@ bool ModelBase::fromJson( const web::json::value& val, bool & outVal )
}
bool ModelBase::fromJson( const web::json::value& val, float & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<float>::quiet_NaN(): static_cast<float>(val.as_double());
return val.is_double();
outVal = (!val.is_double() && !val.is_integer()) ? std::numeric_limits<float>::quiet_NaN(): static_cast<float>(val.as_double());
return val.is_double() || val.is_integer();
}
bool ModelBase::fromJson( const web::json::value& val, double & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
return val.is_double() ;
outVal = (!val.is_double() && !val.is_integer()) ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
return val.is_double() || val.is_integer();
}
bool ModelBase::fromJson( const web::json::value& val, int32_t & outVal )
{