GWT's JSONParser producing incorrect values for numbers.

Posted by WesleyJohnson on Stack Overflow See other posts from Stack Overflow or by WesleyJohnson
Published on 2010-03-25T18:30:35Z Indexed on 2010/03/25 18:33 UTC
Read the original article Hit count: 401

Filed under:
|
|
|

I'm work with GWT and parsing a JSON result from an ASP.NET webservice method that returns a DataTable. I can parse the result into a JSONvalue/JSONObject just fine. The issue I'm having is that one my columns in a DECIMAL(20, 0) and the values that are getting parsed into JSON aren't exact. To demonstrate w/o the need for a WS call, in GWT I threw this together:

String jsonString = "{value:4768428229311981600}";
JSONObject jsonObject = JSONParser.parse( jsonString ).isObject();
Window.alert( jsonObject.toString() );

This in turn alerts:

{"value":4768428229311982000}

I'm under the understanding that GWT's JSONParser is just using eval() to do the parsing, so is this some sort of number/precision issue with JavaScript that I've never been aware of. I'll admit I don't work with numbers that much in JavaScript and I might be able to work around this by changing the .NET WebService to return this column as string, but I'd really rather not do that.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about gwt