从.Net web方法修复JSON日期序列化 [英] Fixing JSON Date serialization from .Net web method

查看:167
本文介绍了从.Net web方法修复JSON日期序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在一个项目中,通过ajax将一个.net类型通过ajax发送给客户端应用程序。我没有问题的对象被序列化并设置到客户端。

I am currently working on a project where I am sending a .Net type via ajax to a client application via ajax. I have no issues with the object being serialized and set to the client.

我遇到问题,当我采取完全相同的对象,并发布回服务器通过一个web方法带有以下错误: / Date(1373950800000)/不是DateTime的有效值。这是非常讨厌的,因为这是微软给我的,但这是除了这一点。

I run into issues when I take the exactly same object and post it back to the server via a web method with the following error: /Date(1373950800000)/ is not a valid value for DateTime. Which is pretty annoying as that is how Microsoft gave it to me, but that's besides the point.

有没有人能快速解决这个问题?我想要一个无缝的方法,而不必在从ajax调用返回之前更改对象。

Does anyone have a quick fix for this? I want a seamless way this can be accomplished without having to change the object right before returning it from the ajax call.

推荐答案

您的问题归结于您正在使用的服务器端JavaScript串行器; JsonDataContractSerializer (ASP.NET MVC的默认序列化程序)或 NewtonSoft Json Serializer (ASP.NET Web API的默认序列化程序)

Your issue comes down to the server-side JavaScript serializer you are using; either JsonDataContractSerializer (default serializer for ASP.NET MVC) or NewtonSoft Json Serializer (default serializer for ASP.NET Web API).

有关这个日期问题的可视示例以及可能的解决方案,请查看 JSON日期在ASP.NET MVC和Web API中不同

For a visual example of this date mangling issue as well as possible solutions, check out JSON Dates are Different in ASP.NET MVC and Web API.

这篇关于从.Net web方法修复JSON日期序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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