杰森日期时间问题 [英] Json Datetime issue

查看:116
本文介绍了杰森日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何强制netwtonsoft json序列化程序进行序列化将datetime属性设置为字符串?

Possible Duplicate:
how to force netwtonsoft json serializer to serialize datetime property to string?

我正在使用Newtonsoft.Json将我的对象转换为JSON文件. 但是我在对象日期时间字段中将DateTime设置为"7/30/2012 8:29:12 PM",但是在JSON文件中却遇到了问题.我正在使用以下格式的DateTime字段:

I am using Newtonsoft.Json to convert my object in to JSON file. But I am having issue with the DateTime, in my object datetime field is set as "7/30/2012 8:29:12 PM" but in JSON file. I am getting DateTime field in this format:

"\/Date(1343660352227+0530)\/".

我需要以与对象相同的格式获取DateTime.是否有可能?我该怎么做才能获得相同的格式?

I need to get the DateTime in the same format as that of the object. Is it possible? What should I do in order to get the same format?

推荐答案

我得到了如下解决方案.

I got the solution as follow.

JsonConvert.SerializeObject(this, Formatting.None, new IsoDateTimeConverter() {
    DateTimeFormat = "yyyy-MM-dd hh:mm:ss"
});

这是答案:

如何强制使用netwtonsoft json序列化器将datetime属性序列化为字符串?

这篇关于杰森日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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