3

What are the pros and cons of using the following two JSON serialization methods:

  1. System.Web.Script.Serialization
  2. DataContractJsonSerializer
Mat
  • 202,337
  • 40
  • 393
  • 406
user496949
  • 83,087
  • 147
  • 309
  • 426
  • 1
    possible duplicate of [System.Web.Script.Serialization.JavaScriptSerializer or System.Runtime.Serialization.Json.DataContractJsonSerializer?](http://stackoverflow.com/questions/831697/system-web-script-serialization-javascriptserializer-or-system-runtime-serializat) – RPM1984 Nov 04 '10 at 08:56
  • 3
    That title reminds me of an old joke, "What's the difference between a duck?" – Marcelo Cantos Nov 04 '10 at 09:04
  • It doesn't quack when it's dead? – jgauffin Nov 04 '10 at 10:12

1 Answers1

1

DataContractJsonSerializer

The primary purpose of the DataContractJsonSerializer is to be used with WCF, since one serialization is a big focus of WCF. Also, it is also better equipped to handle complex classes which have only certain properties available for serialization. This class is more strongly typed, has more knowledge about the type(s) it's handling and better error handling for badly-formed JSON.

.

JavaScriptSerializer

This class on the other hand is much better equipped for quick serialization, it's a more cowboy approach. There's less error checking and less control over what properties which are serialized.

Reference

Community
  • 1
  • 1
Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66