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

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

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

3条回答
  •  甜味超标
    2021-02-05 04:03

    The JavaScriptSerializer is marked as obsolete in framework 3.5. You shouldn't use it for that reason. However, back to your question. The JavaScriptSerializer doesn't require classes to be marked as [Serializable] or as [DataContract] but the DataContractJsonSerializer does. If you have compiled classes that you can't mark with attributes, you may want to use the older JSON serializer.

提交回复
热议问题