JSON响应长舍入或损坏 [英] JSON Response Long is Rounded or Corrupted

查看:46
本文介绍了JSON响应长舍入或损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将JSON从服务器发送到客户端. JSON包含long.

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:

  • 发送的服务器端号码是:1036647050030089506
  • 收到的客户端号码是:1036647050030089500
  • The server side number sent is: 1036647050030089506
  • The client side number received is: 1036647050030089500

为什么会这样,我该如何解决?

Why is this happening and how can I fix this?

服务器端代码:

Post["team", true] = async (parameters, ct) =>
{
    var team = this.Bind<Team>();
    team.Id = 1036647050030089506;

    Console.WriteLine("Response: " + team.Id);
    return Response.AsJson(team);
};

客户端代码:

$.ajax({
    url: '/api/team',
    type: 'POST',
    dataType: "json",
    success: function (response) {
        alert("Response: " + response.id);
    }
});

推荐答案

好像您希望将其作为字符串发送.请参阅此问题,以获取有关如何js处理大数字的更多详细信息.剧透警报:糟糕...但是我仍然爱你javascript ...仍然爱你.

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.

这篇关于JSON响应长舍入或损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆