使用自定义解析日期格式JSON.Net [英] Parse custom date format using JSON.Net

查看:180
本文介绍了使用自定义解析日期格式JSON.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了以下格式

"launch_date": 1250553600

我应该如何修改以下以包括自定义DateTime解析器,让我这个数字转换成的DateTime 对象?

How should I modify the following to include a custom DateTime parser that allows me to convert that number into a DateTime object?

JsonConvert.DeserializeObject<NTask>(json);

public sealed class NTask
{
    public DateTime launch_date { get; set; }
}



我也可以使用,然后解析它在另一个领域,但我宁愿避免这样做,并有 JsonConvert 自动通过一些转换器解析为DateTime。

Alternatively I could use long and then parse it in another field but I'd rather avoid doing that, and have JsonConvert automatically parse it to DateTime through some converter.

推荐答案

您会想使用的 JSONConverter 以帮助管理翻译。请参见这stackapps回答了解详细信息。

You're going to want to use a JSONConverter to help manage the translation. See this stackapps answer for more detail.

这篇关于使用自定义解析日期格式JSON.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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