【发布时间】:2015-04-11 19:05:42
【问题描述】:
I'm going by this tutorial 并试图弄清楚如何拥有没有自动属性的 DataMember。基本上我有一个字段是纪元格式的日期时间,我希望属性是 DateTime,所以我试图在属性的获取中进行转换。我不确定如何准确格式化。
由于请求了代码,请查看以下内容。 :
// The date looks like this in the JSON
"someEpochDateTime": 1428785212000,
// I thought I could work around it using the following code, however
// I get a warning saying someEpochDateTime is never set.
[DataMember(Name = "someEpochDateTime")]
private long someEpochDateTime;
public DateTime test
{
get { return DateTimeConverter.FromUnixTime(someEpochDateTime); }
}
【问题讨论】:
-
以下是如何进行转换:stackoverflow.com/questions/2883576/…。在
DateTimegetter 和 setter 中调用此代码 -
请显示您当前的代码。
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
更新添加了一些代码。
标签: c# json rest properties datacontract