"EnTerr" wrote:
Ha! That's a head-scratcher. It is worth mentioning that int`s are 32-bit in BS, no bignums and parseJSON() is behaving reasonably:
Perhaps, but parsing as a Double instead of a Float seems to give better results. I recently had to overcome this in some JSON that had date/times in milliseconds, using this custom AsDouble() hack to convert the string after the regex replace...
Function AsDouble(input As Dynamic) As Double
output# = 0
If IsString(input) Then
If input.Len() <= 9 Then
output# = input.ToInt()
Else
' Big string, so break it into parts and build the double
low = input.Mid(input.Len() - 9, 9).ToInt()
high = input.Mid(0, input.Len() - 9).ToInt()
output# = high
output# = output# * 1000000000
output# = output# + low
End If
Else If IsInteger(input) Or IsFloat(input) Then
output# = input
End If
Return output#
End Function
If you try to convert the string to a Float instead of a Double, you get completely different results (well, not
completely, but different enough to cause a headache if you need accuracy).
"EnTerr" wrote:
miss cases where \t or multiple spaces are present between : and the number (in dictionary)
Oops. I tried to account for that, but mistakenly used "(\s?)" instead of "(\s*)". The regex should be:
:(\s*)([0-9]{9,})
"EnTerr" wrote:
- miss numbers within a list, e.g. [1, 1234567890, 3]
- mangle strings that contain long numbers preceded by :, e.g. {"text": "this is how a 10-digit number looks like: 1234567890"}
Good catch, and certainly worth mentioning as a caveat.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)