使用JSON序列化到/反序列化时间跨度 [英] Using Json to Serialize/Deserialize TimeSpan

查看:347
本文介绍了使用JSON序列化到/反序列化时间跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图反序列化/序列化一个时间跨度,

I'm trying to deserialize/serialize a timespan,

但是当JSON是送它设置为00:00:00
这是甚至可能这样做?

but when the json is send it's set to 00:00:00 is this even possible to do?

谢谢!
-Kevin

Thanks! -Kevin

顺便说一下,语言是C#,使用Visual Studio 2008。

Btw, Language is C#, using Visual Studio 2008.

推荐答案

我想通了,很显然这是一个MS设计缺陷...

I figured it out, Apparently it's a MS design flaw...

由于时间跨度不能是一个无参数的对象。 XML无法重新创建它。

Since TimeSpan cannot be a parameterless object. XML cannot recreate it.

看看这个网站。
http://forums.silverlight.net/forums/p/51793 /135450.aspx

所以。因此,时间跨度不能转换。一个简单的方法做,这是
更改的时间跨度为一个字符串,然后送过来的字符串。
,并使用TimeSpan.TryParse(字符串);

So. Therefore TimeSpan cannot be converted. An easy way to do this is to change the timespan into a string, and then send the string over. and use TimeSpan.TryParse(String);

这篇关于使用JSON序列化到/反序列化时间跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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