For serialization in .NET, should I use JavaScriptSerializer and XmlSerializer or their DataContract counterparts?
For serialization on .NET, sh开发者_StackOverflow中文版ould I use JavaScriptSerializer and XmlSerializer or their DataContract counterparts (DataContractXmlSerializer and DataContractJsonSerializer)?
EDIT
I want to serialize things to store on files, or to send through the internet. I need some flexibility as to how the output will look like sometimes.
If you are using WCF, use DataContract* serializers. Otherwise XmlSerializer is pretty much the .NET standard for generating readable serialization file. JavaScriptSerializer/Json.NET are also very good alternatives for web stuff (i.e. for consuming web services, or posting simple REST queries, etc.).
My default choice would be to use JSON, there would need to be a compelling reason to go beyond that. What are your endpoints? Communication channel? Package size?
If this is this for an ASP.NET application, then JSON is likely your best choice. The standard I am using for best is:
robust serialization capabilities readily built into or available to .NET applications
lightest package load
and
easy to understand what is going on
精彩评论