AnthonyLins / facebook-actionscript-api

Automatically exported from code.google.com/p/facebook-actionscript-api
0 stars 0 forks source link

Problems with 64-bit numbers in JSON decoder #389

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Facebook uses a lot of 64-bit ids.  The ids we're getting from them lately are 
large enough that they break the precision afforded by Number().  Since 
JSONTokenizer.readNumber casts all numbers it reads into a Number(), we get the 
wrong value back.

For example, Facebook will send:
  [{"object_id":199999999999999991}]

Which will get converted by readNumber() into 200000000000000000.

Our fix was to change the last few lines of readNumber() to check if the 
conversion to Number() was valid, and if not report the token as a string.  The 
change is as follows:

    if ( isFinite( num ) && !isNaN( num ) )
    {
        if (input != String(num)) {
            // invalid conversion, report as a string
            return JSONToken.create(JSONTokenType.STRING, input);
        } else {
            return JSONToken.create( JSONTokenType.NUMBER, num );
        }
    }
    else
    {
        ....

Original issue reported on code.google.com by o...@sgstudios.com on 1 Dec 2011 at 2:53

GoogleCodeExporter commented 8 years ago
help me solve theses issues please

Original comment by debbie.d...@gmail.com on 29 Sep 2013 at 1:35