How do I get the JavaScriptSerializer from System.Web.Extensions to use CultureInfo.CurrentCulture?
I’m getting exceptions deserializing DD/MM/YYYY DateTimes, as it’s currently expecting them in US format, which is incorrect for our application.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Per the MDSN notes on JavaScriptSerializer:
You’ll need to register a
JavaScriptConverterforDateTimethat handles your type:Bear in mind you’ll need to account for what your JSON will actually have in terms of object property names (you’re probably using a name other than “Time”).
Register it on your JavaScriptSerializer:
Finally, note that there’s more that can be done, and this is only an example to build on. Explicitly, it is searching for dictionary items with the name “Time”, and isn’t handling parse failures. You might have more than just one name for fields using DateTime.