JSON数据int64类型返回错误的值 [英] JSON data int64 type return wrong value

查看:377
本文介绍了JSON数据int64类型返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们



i小英文,对不起:)



我的示例代码是那个(它是asp.net mvc)



model.cs



 < span class =code-keyword> public   class  TestModel 
{
public string 名称{ get ; set ; }
public Int64 值{ get ; set ; }
}





controller.cs



  public  ActionResult Test()
{
TestModel model = new TestModel {Name = 测试,值= 1000000000000000001 };

return Json(model,JsonRequestBehavior.AllowGet);
}





view.cshtml



 <   script    类型  =  text / javascript < span class =code-keyword>>  
$(function(){
$ .ajax({
type:'GET',
url: / test / Test,
data:{},
})。done(function(result){
alert(JSON.stringify(result));
}) ;
});
< / script >





但警报结果返回{名称:测试,价值:1000000000000000000}



价值返回1000000000000000000(来源价值是1000000000000000001)



你能告诉我解决方案吗?



谢谢。

解决方案

(function(){


.ajax({
类型:'GET',
url:/ Test / Test,
data:{},
})。done(function(result){
alert (JSON.stringify(result));
});
});
< / script >





但警报结果返回{名称:测试,价值:1000000000000000000}



价值返回1000000000000000000(来源价值是1000000000000000001)



你能告诉我解决方案吗?



谢谢。


Javascript没有64位整数类型。数字将由 数字表示类型 [ ^ ],这是一个64位双精度浮点类型。



Number 类型可以存储的最大整数是 9007199254740992 ;任何大于此的东西都会失去精确度。


hey guys

i little english, sorry :)

my sample code is that (it is asp.net mvc)

model.cs

public class TestModel
{
    public string Name { get; set; }
    public Int64 Value { get; set; }
}



controller.cs

public ActionResult Test()
{
     TestModel model = new TestModel { Name = "Test", Value = 1000000000000000001 };

     return Json(model, JsonRequestBehavior.AllowGet);
}



view.cshtml

<script type="text/javascript">
    $(function () {
        $.ajax({
            type: 'GET',
            url: "/Test/Test",
            data: {},
        }).done(function (result) {
            alert(JSON.stringify(result));
        });
    });
</script>



but alert result returns {"Name":"Test","Value":1000000000000000000}

the "Value" return 1000000000000000000 (source value is 1000000000000000001)

can you tell me solution?

thanks.

解决方案

(function () {


.ajax({ type: 'GET', url: "/Test/Test", data: {}, }).done(function (result) { alert(JSON.stringify(result)); }); }); </script>



but alert result returns {"Name":"Test","Value":1000000000000000000}

the "Value" return 1000000000000000000 (source value is 1000000000000000001)

can you tell me solution?

thanks.


Javascript doesn't have a 64-bit integer type. Numbers will be represented by the Number type[^], which is a 64-bit double precision floating-point type.

The largest integer that the Number type can store is 9007199254740992; anything larger than that will lose precision.


这篇关于JSON数据int64类型返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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