JSON Response Long is Rounded or Corrupted [duplicate]

北城余情 提交于 2021-02-10 12:00:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!