Silverlight和WPF中DataContractJsonSerializer對時間的處理差異

來源:互聯網
上載者:User

標籤:blog   http   2014   div   sp   log   on   c   時間   

原創文章轉載請註明出處:@協思, http://zeeman.cnblogs.com

Silverlight脫胎於WPF,他們的行為不完全並不完全相同,DataContractJsonSerializer對時間處理有一個坑。

我們知道.NET在序列化實體為JSON的時候,會將DateTime處理為【/Date(xxxxx)】的字串。如果Client端將這個屬性不定義為DateTime,而定義為String會發生什麼呢? 常規思維下我們都會認為String Value就是【/Date(xxxxx)】,在WPF中也確實是這樣,而Silverlight則會將轉換為時間格式的字串。 

用Reflector來看它對日期的判斷:

 

再看對於時區的檢查

 

Silverlight版本的DataContractJsonSerializer將【/Date(xxxxx)】判定為DateTime, 並且轉換為本地時間,再將這個時間轉換為String。

Silverlight和WPF中DataContractJsonSerializer對時間的處理差異

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.