久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <i id='6aXsR'><tr id='6aXsR'><dt id='6aXsR'><q id='6aXsR'><span id='6aXsR'><b id='6aXsR'><form id='6aXsR'><ins id='6aXsR'></ins><ul id='6aXsR'></ul><sub id='6aXsR'></sub></form><legend id='6aXsR'></legend><bdo id='6aXsR'><pre id='6aXsR'><center id='6aXsR'></center></pre></bdo></b><th id='6aXsR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6aXsR'><tfoot id='6aXsR'></tfoot><dl id='6aXsR'><fieldset id='6aXsR'></fieldset></dl></div>
    <tfoot id='6aXsR'></tfoot>
      <bdo id='6aXsR'></bdo><ul id='6aXsR'></ul>

    <small id='6aXsR'></small><noframes id='6aXsR'>

    <legend id='6aXsR'><style id='6aXsR'><dir id='6aXsR'><q id='6aXsR'></q></dir></style></legend>
      1. 使用 Json.Net 序列化時(shí)指定自定義 DateTime 格式

        Specifying a custom DateTime format when serializing with Json.Net(使用 Json.Net 序列化時(shí)指定自定義 DateTime 格式)
        <legend id='IPFJ5'><style id='IPFJ5'><dir id='IPFJ5'><q id='IPFJ5'></q></dir></style></legend>
          • <bdo id='IPFJ5'></bdo><ul id='IPFJ5'></ul>

                <tbody id='IPFJ5'></tbody>
                <i id='IPFJ5'><tr id='IPFJ5'><dt id='IPFJ5'><q id='IPFJ5'><span id='IPFJ5'><b id='IPFJ5'><form id='IPFJ5'><ins id='IPFJ5'></ins><ul id='IPFJ5'></ul><sub id='IPFJ5'></sub></form><legend id='IPFJ5'></legend><bdo id='IPFJ5'><pre id='IPFJ5'><center id='IPFJ5'></center></pre></bdo></b><th id='IPFJ5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IPFJ5'><tfoot id='IPFJ5'></tfoot><dl id='IPFJ5'><fieldset id='IPFJ5'></fieldset></dl></div>

                <small id='IPFJ5'></small><noframes id='IPFJ5'>

                  <tfoot id='IPFJ5'></tfoot>

                  本文介紹了使用 Json.Net 序列化時(shí)指定自定義 DateTime 格式的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在開發(fā)一個(gè) API 來使用 ASP.NET Web API 公開一些數(shù)據(jù).

                  I am developing an API to expose some data using ASP.NET Web API.

                  在其中一個(gè) API 中,客戶端希望我們以 yyyy-MM-dd 格式公開日期.我不想為此更改全局設(shè)置(例如 GlobalConfiguration.Configuration.Formatters.JsonFormatter),因?yàn)樗浅L囟ㄓ谠摽蛻舳?我確實(shí)在為多個(gè)客戶開發(fā)解決方案.

                  In one of the API, the client wants us to expose the date in yyyy-MM-dd format. I don't want to change the global settings (e.g. GlobalConfiguration.Configuration.Formatters.JsonFormatter) for that since it is very specific to this client. And I do developing that in a solution for multiple clients.

                  我能想到的解決方案之一是創(chuàng)建一個(gè)自定義 JsonConverter,然后將其放入我需要進(jìn)行自定義格式設(shè)置的屬性

                  One of the solution that I could think of is to create a custom JsonConverter and then put that to the property I need to do the custom formatting

                  例如

                  class ReturnObjectA 
                  {
                      [JsonConverter(typeof(CustomDateTimeConverter))]
                      public DateTime ReturnDate { get;set;}
                  }
                  

                  只是想知道是否有其他簡(jiǎn)單的方法可以做到這一點(diǎn).

                  Just wondering if there is some other easy way of doing that.

                  推薦答案

                  你在正確的軌道上.既然你說你不能修改全局設(shè)置,那么下一個(gè)最好的事情是根據(jù)需要應(yīng)用 JsonConverter 屬性,正如你所建議的那樣.原來 Json.Net 已經(jīng)有一個(gè)內(nèi)置的 IsoDateTimeConverter 可讓您指定日期格式.不幸的是,您不能通過 JsonConverter 屬性設(shè)置格式,因?yàn)樵搶傩缘奈ㄒ粎?shù)是一個(gè)類型.但是,有一個(gè)簡(jiǎn)單的解決方案:將 IsoDateTimeConverter 子類化,然后在子類的構(gòu)造函數(shù)中指定日期格式.在需要的地方應(yīng)用 JsonConverter 屬性,指定您的自定義轉(zhuǎn)換器,然后您就可以開始了.以下是所需的全部代碼:

                  You are on the right track. Since you said you can't modify the global settings, then the next best thing is to apply the JsonConverter attribute on an as-needed basis, as you suggested. It turns out Json.Net already has a built-in IsoDateTimeConverter that lets you specify the date format. Unfortunately, you can't set the format via the JsonConverter attribute, since the attribute's sole argument is a type. However, there is a simple solution: subclass the IsoDateTimeConverter, then specify the date format in the constructor of the subclass. Apply the JsonConverter attribute where needed, specifying your custom converter, and you're ready to go. Here is the entirety of the code needed:

                  class CustomDateTimeConverter : IsoDateTimeConverter
                  {
                      public CustomDateTimeConverter()
                      {
                          base.DateTimeFormat = "yyyy-MM-dd";
                      }
                  }
                  

                  如果您不介意也有時(shí)間,您甚至不需要子類化 IsoDateTimeConverter.它的默認(rèn)日期格式是 yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK(見 源代碼).

                  If you don't mind having the time in there also, you don't even need to subclass the IsoDateTimeConverter. Its default date format is yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK (as seen in the source code).

                  這篇關(guān)于使用 Json.Net 序列化時(shí)指定自定義 DateTime 格式的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時(shí)忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標(biāo)簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯(cuò)誤的 XML)

                  <small id='L3agq'></small><noframes id='L3agq'>

                    <bdo id='L3agq'></bdo><ul id='L3agq'></ul>

                  • <i id='L3agq'><tr id='L3agq'><dt id='L3agq'><q id='L3agq'><span id='L3agq'><b id='L3agq'><form id='L3agq'><ins id='L3agq'></ins><ul id='L3agq'></ul><sub id='L3agq'></sub></form><legend id='L3agq'></legend><bdo id='L3agq'><pre id='L3agq'><center id='L3agq'></center></pre></bdo></b><th id='L3agq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='L3agq'><tfoot id='L3agq'></tfoot><dl id='L3agq'><fieldset id='L3agq'></fieldset></dl></div>
                      <tbody id='L3agq'></tbody>
                        <legend id='L3agq'><style id='L3agq'><dir id='L3agq'><q id='L3agq'></q></dir></style></legend>

                          <tfoot id='L3agq'></tfoot>

                            主站蜘蛛池模板: 久久久妇女国产精品影视 | 亚洲精品大全 | 亚洲情视频 | 国产成人亚洲精品 | 久久精品a| 亚洲精品粉嫩美女一区 | 91色综合| 一区二区三区免费 | 91视频久久 | 日本天堂视频在线观看 | 欧美在线观看一区二区 | 日韩欧美精品 | 日操操 | 夜夜爽99久久国产综合精品女不卡 | 精品欧美黑人一区二区三区 | 一区二区三区在线 | 天天爱综合| 国产精品视频久久 | 欧美第一页 | 小川阿佐美pgd-606在线 | 久久久久网站 | 成人精品鲁一区一区二区 | 欧美伊人| 欧美日韩一区精品 | 91久久精品一区 | 亚洲精品18 | 日日干天天干 | 国产探花在线精品一区二区 | 国产女人与拘做受免费视频 | 欧美精品一区二区在线观看 | 精品91久久久 | jizz18国产 | 青青草av在线播放 | 中文字幕国产高清 | 欧产日产国产精品视频 | 久久久国产一区二区三区四区小说 | 久久精品一区二区三区四区 | 免费a级毛片在线播放 | 久久综合久色欧美综合狠狠 | 欧美日韩亚洲成人 | 黄色欧美在线 |