<bdo id='wrcha'></bdo><ul id='wrcha'></ul>
    <tfoot id='wrcha'></tfoot>
  1. <legend id='wrcha'><style id='wrcha'><dir id='wrcha'><q id='wrcha'></q></dir></style></legend>

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

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

      如何创建 JSON.NET 日期到字符串自定义转换器

      时间:2023-08-22
      <i id='iWRSr'><tr id='iWRSr'><dt id='iWRSr'><q id='iWRSr'><span id='iWRSr'><b id='iWRSr'><form id='iWRSr'><ins id='iWRSr'></ins><ul id='iWRSr'></ul><sub id='iWRSr'></sub></form><legend id='iWRSr'></legend><bdo id='iWRSr'><pre id='iWRSr'><center id='iWRSr'></center></pre></bdo></b><th id='iWRSr'></th></span></q></dt></tr></i><div id='iWRSr'><tfoot id='iWRSr'></tfoot><dl id='iWRSr'><fieldset id='iWRSr'></fieldset></dl></div>

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

          <tfoot id='iWRSr'></tfoot>
            <tbody id='iWRSr'></tbody>

            <bdo id='iWRSr'></bdo><ul id='iWRSr'></ul>
          • <legend id='iWRSr'><style id='iWRSr'><dir id='iWRSr'><q id='iWRSr'></q></dir></style></legend>
              1. 本文介绍了如何创建 JSON.NET 日期到字符串自定义转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                有人可以告诉我如何创建自定义转换器

                Could someone tell me please how I can create a custom converter

                我知道我可以使用 JSON.NET ISODateConvertor,但我想要的是具体的,我只想在响应时将值作为日/月/年"字符串发送.

                I know I can use JSON.NET ISODateConvertor, but what I want is specific, I just want to send the value as "day/month/year" string on response.

                推荐答案

                像这样?

                string str = JsonConvert.SerializeObject(new DateTimeClass(), new MyDateTimeConvertor());
                
                public class DateTimeClass
                {
                    public DateTime dt;
                    public int dummy = 0;
                }
                
                public class MyDateTimeConvertor : DateTimeConverterBase
                {
                    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
                    {
                        return DateTime.Parse(reader.Value.ToString());
                    }
                
                    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
                    {
                        writer.WriteValue( ((DateTime)value).ToString("dd/MM/yyyy") );
                    }
                }
                

                这篇关于如何创建 JSON.NET 日期到字符串自定义转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Newtonsoft 忽略属性? 下一篇:JSON.NET 序列化 JObject 而忽略空属性

                相关文章

                最新文章

                1. <i id='CXO2E'><tr id='CXO2E'><dt id='CXO2E'><q id='CXO2E'><span id='CXO2E'><b id='CXO2E'><form id='CXO2E'><ins id='CXO2E'></ins><ul id='CXO2E'></ul><sub id='CXO2E'></sub></form><legend id='CXO2E'></legend><bdo id='CXO2E'><pre id='CXO2E'><center id='CXO2E'></center></pre></bdo></b><th id='CXO2E'></th></span></q></dt></tr></i><div id='CXO2E'><tfoot id='CXO2E'></tfoot><dl id='CXO2E'><fieldset id='CXO2E'></fieldset></dl></div>

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

                    <tfoot id='CXO2E'></tfoot>
                      <bdo id='CXO2E'></bdo><ul id='CXO2E'></ul>
                    <legend id='CXO2E'><style id='CXO2E'><dir id='CXO2E'><q id='CXO2E'></q></dir></style></legend>