17

JavaScriptSerializer is not obsolete after .net 3.5 SP1. Should I uses JavaScriptSerializer or the prior recommended DataContractJsonSerializer?. Also why it was made obsolete?

suhair
  • 10,895
  • 11
  • 52
  • 63
  • 1
    Just to add more - JavaScriptSerializer and DataContractJsonSerializer aren't always compatible with each-other (DateTime, IIRC, is a pain). – Marc Gravell Feb 11 '09 at 13:08

2 Answers2

12

I'd happily use JavaScriptSerializer - but if in doubt, consider a third option - Json.NET. Because it is 3rd party, it is unrelated to the MS decisions... that is a double-edged sword, of course - but it is often easier to get a minor fix applied to a standalone 3rd-party libary.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • sorry i had to put this up here in comments but,using `.net 2.0 asmx service` which way should i go `DataContractJsonSerializer`,'JavaScriptSerializer' or `http://jayrock.berlios.de` i don't know if JSON.net is 2.0 compatible. We are just building a widget system and are relaying widgets as JSON data from webmethods. – Deeptechtons Feb 15 '12 at 09:56
  • @Deeptechtons well, JavaScriptSerializer isn't an option on 2.0, and neither is DataContractJsonSerializer. Frankly, DataContractJsonSerializer tends to produce atypical json. I would either: upgrade to 3.5/4.0 and use JavaScriptSerializer, or see if JSON.net etc are 2.0 friendly – Marc Gravell Feb 15 '12 at 10:38
  • thank you & btw is JSON - RPc any different from webmethods returning object?http://stackoverflow.com/questions/9291423/json-rpc-libraries-for-use-with-net – Deeptechtons Feb 15 '12 at 10:47
6

I have not seen definitive explanation. There were quite a few people upset when JavaScriptSerializer was made obsolete.

Scott Gu made this comment on his blog saying that he thought marking it as obsolete didn't make sense.

The JavaScriptSerializer is currently marked obsolete - although I'm not sure why (was going to ask someone about this today). It is very handy. Note that obsolete doesn't mean removal in .NET 3.5 - it will be supported at least another version or two (or longer if I can convince them ).

I guess maybe he did convince them :-)

I have continued to use JavaScriptSerializer as its much more straight forward than the DataContractJsonSerializer.

Brownie
  • 7,688
  • 5
  • 27
  • 39
  • 2
    Since the MVC team uses JavaScriptSerializer so heavily, it's unlikely it will be dropped in the future since MVC has caught such fire. – Paul Alexander Jan 05 '10 at 04:20
  • Of course [webAPI uses Json.Net](https://blogs.msdn.microsoft.com/henrikn/2012/02/17/using-json-net-with-asp-net-web-api/) as standard. So microsoft are no longer chained to using either of these technologies. I believe there is talk of combining web api technologies with MVC so how long this dependency continues to be maintained is now questionable. IMO Json.Net wins every time. – Liam Apr 04 '17 at 13:16