ErikMinekus / sm-ripext

SourceMod REST in Pawn Extension
https://forums.alliedmods.net/showthread.php?t=298024
GNU General Public License v3.0
133 stars 38 forks source link

NodeJS: float certain values as an integer #45

Closed Wend4r closed 2 years ago

Wend4r commented 3 years ago

When does response from the backend on NodeJS, Rest In Pawn cannot read this integer float values through JSONObject.GetFloat().

> JSON.stringify({"float": 1.0})
'{"float":1}'

But JSONObject.GetFloat() works in the case of

> JSON.stringify({"float": 1.1})
'{"float":1.1}'

I suggest to make reading of integers even as float.

ErikMinekus commented 3 years ago

JavaScript does not have distinct types for integers and floats, so JSON.stringify() outputs 1.0 as 1, which I can only interpret as an integer. JSONObject.FromFile() and .FromString() do support the JSON_DECODE_INT_AS_REAL flag, which interprets all numbers as floats, but it's currently not possible to use decoding flags with an HTTP response. I will consider that for the future.

Wend4r commented 3 years ago

With #52, I can control float and integer values.