问题
I am sending JSON from the server to client side. The JSON contains a long
.
It appears that the number is being rounded or something because:
- The server side number sent is:
1036647050030089506
- The client side number received is:
1036647050030089500
Why is this happening and how can I fix this?
Server side code:
Post["team", true] = async (parameters, ct) =>
{
var team = this.Bind<Team>();
team.Id = 1036647050030089506;
Console.WriteLine("Response: " + team.Id);
return Response.AsJson(team);
};
Client side code:
$.ajax({
url: '/api/team',
type: 'POST',
dataType: "json",
success: function (response) {
alert("Response: " + response.id);
}
});
回答1:
Looks like you'll want to send it as a string. See this question for more details about how js handles big ol' numbas. Spoiler alert: poorly...but I still love you javascript...still love you.
来源:https://stackoverflow.com/questions/31622895/json-response-long-is-rounded-or-corrupted