lamy Posted February 12, 2014 Posted February 12, 2014 i have a page that sends to a webapi via WebClient which has a DateTime value as one of the parameter, for some reason after serializing it with JavaScriptSerializer it takes -8 out of the value here's what i tested in C# public class MyParam { public string param1 { get; set; } public DateTime param2 { get; set; } } JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(param); // param = MyParam json = serializer.Serialize(json); MyParam test = serializer.Deserialize<MyParam>(json); // less 8 hours of original value Quote slow down when you need to hurry, stop when you need to move on, look back when you need to forget, or you might slip and leave sanity
Administrators PlausiblyDamp Posted February 12, 2014 Administrators Posted February 12, 2014 It looks like it is failing to handle timezone offsets correctly, in all honesty I don't use JavaScriptSerializer myself as I have found several issues with it. http://james.newtonking.com/json is a far better library for handling this kind of thing (even Micorsoft use it in preference to their own code in the MVC framework). In fact you can install it directly with Nuget (just search for json.net) if you prefer an easy life. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
lamy Posted February 13, 2014 Author Posted February 13, 2014 It looks like it is failing to handle timezone offsets correctly, in all honesty I don't use JavaScriptSerializer myself as I have found several issues with it. http://james.newtonking.com/json is a far better library for handling this kind of thing (even Micorsoft use it in preference to their own code in the MVC framework). In fact you can install it directly with Nuget (just search for json.net) if you prefer an easy life. thanks :) Quote slow down when you need to hurry, stop when you need to move on, look back when you need to forget, or you might slip and leave sanity
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.