c# - 使用 JSON 序列化/反序列化 TimeSpan

标签 c# json web-services json.net

我正在尝试使用 Newtonsoft.Json.JsonConvert 反序列化/序列化时间跨度,但是当发送 JSON 时,它被设置为 00:00:00。

这甚至可以做到吗?

最佳答案

我尝试了#Jessycormier 的方法,但它对我不起作用。 我运行 DataContractJsonSerializer 以查看它会生成什么,我发现它给了我一个看起来更像这样的值。

{"PassedTimeSpan":"P1DT2H3M4S"}

上面显示的值是 1 天 2 小时 3 分 4 秒。

所以看起来格式是:

[-]P[{days}D][T[{hours}H][{min}M][{sec}S]]

地点:

- Indicates negative timespan, omitted for positive values
P must be the first character (unless negative time value)
T must precede the time portion of the timespan.
[] = optional part that may be omitted if 0.

关于c# - 使用 JSON 序列化/反序列化 TimeSpan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3232701/

相关文章:

c# - LINQ Left 加入 group by 并计数

javascript - 使用另一个 json 对象从 json 对象中删除特定内容

jquery - 是否应该使用网络服务来创建整个网站?

c# - 使用HttpClient.GetFromJsonAsync(),如何处理基于HttpStatusCode的HttpRequestException而无需额外的SendAsync调用?

c# - 在 C# 中为图像添加颜色

c# - 以编程方式禁用 Windows 中的密码复杂性

ios - 将多个图像发送到服务器

javascript - 使用 stringify 将 javascript 关联数组转换为 json 对象,反之亦然

java - 休息网络服务 : How to accept a list of parameter

web-services - RESTful API 是否被过度使用/误用?