Custom JavaScriptConverter for DateTime?

前端 未结 10 730
走了就别回头了
走了就别回头了 2020-12-02 19:18

I have an object, it has a DateTime property... I want to pass that object from an .ashx handler back to a webpage via AJAX/JSON... I don\'t want to use 3rd party controls..

10条回答
  •  北海茫月
    2020-12-02 19:42

    There is actually a nice clean way to do this without knowing the wrapper type or even needing a wrapper object.

    You use JavaScriptConverter to convert your object to a Uri that also implements IDictionary. JavaScriptSerializer will serialize this as a string.

    This hack is described here: Custom DateTime JSON Format for .NET JavaScriptSerializer

提交回复
热议问题