ufna / VaRest

REST API plugin for Unreal Engine 4 - we love restfull backend and JSON communications!
https://www.unrealengine.com/marketplace/en-US/product/varest-plugin
MIT License
1.08k stars 296 forks source link

Decode Json and Get Number Field return a wrong number #96

Closed fungiboletus closed 7 years ago

fungiboletus commented 7 years ago

Hi,

Using VaRest 1.1-r16, it seems that a wrong number is sometimes returned.

2017-03-10 18_19_16-multitouchtests - unreal editor 2017-03-10 18_19_08-multitouchtests - unreal editor

The JSON string is {"Id":16842749}

And 16842749 != 16842748 indeed.

fungiboletus commented 7 years ago

It seems to be a bug from Unreal and not VaRest.

It works with double though.

FString jsonDocument(TEXT("{\"Id\":16842749}"));
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
TSharedRef< TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create(jsonDocument);

if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
    float numberFloat = JsonObject->GetNumberField(FString(TEXT("Id")));
    double numberDouble = JsonObject->GetNumberField(FString(TEXT("Id")));

    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow,
        FString::Printf(TEXT("Id float: %f\nId double: %f"),
            numberFloat, numberDouble));
}

2017-03-10 23_03_06-demarrer

fungiboletus commented 7 years ago

Ok, so it's a float issue. Float are not good to represent big numbers.

Unreal only implements the double, and VaRest casts it to float, because you can't use double in blueprints.

Could VaRest implement a int32 GetIntegerField ?

ufna commented 7 years ago

Yep, it's a float issue.

Thanks for pull request! :)