从 .Net Web 方法修复 JSON 日期序列化

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

问题描述

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

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).

有关此日期修改问题的直观示例以及可能的解决方案,请查看 ASP.NET MVC 和 Web API 中的 JSON 日期不同.

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 日期序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)