System.Web.Script.Serialization.JavaScriptSerializer or System.Runtime.Serialization.Json.DataContractJsonSerializer?

后端 未结 3 1692
太阳男子
太阳男子 2021-02-05 03:41

What\'s the difference between the two? Why would you use one over the other?

3条回答
  •  攒了一身酷
    2021-02-05 03:49

    Found here: http://aaron-powell.spaces.live.com/blog/cns!91A824220E2BF369!150.entry

    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.

    Update

    As the above link is dead, here is another link: http://kb.cnblogs.com/a/1454030.

提交回复
热议问题