JSON数据int64类型返回错误的值 [英] JSON data int64 type return wrong value
问题描述
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 theNumber
type[^], which is a 64-bit double precision floating-point type.
The largest integer that theNumber
type can store is9007199254740992
; anything larger than that will lose precision.
这篇关于JSON数据int64类型返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!