How datetime is processed when JSON is serialized

Source: Internet
Author: User

The. NET JSON serializer, JavaScriptSerializer and DataContractJsonSerializer, are serialized into Microsoft's datetime JSON format, e.g. "\/date ( 1198908717056) \ "

If you change the JSON serializer to json.net, you may encounter problems with serializing the DateTime format.

The behavior of json.net is like this.

<=4.5, also serialized into Microsoft's datetime JSON format, e.g. "\/date (1198908717056+0800) \ \".

>4.5, serialized into ISO Standard time format, "2016-05-05t14:59:30.4617225+08:00"

If you want to make Json.NET (>4.5) default also output to Microsoft's datetime JSON format solution as follows:

var settings = new Jsonserializersettings ();

Settings. Dateformathandling = dateformathandling.microsoftdateformat;//compatible with <=4.5 version, default serialization to Microsoft's datetime JSON format, e.g. "\/date ( 1198908717056+0800)/", if you want to output ISO standard time, you can set it through DateTimeFormat.

Code such as.

How datetime is processed when JSON is serialized

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.