.NET 4 是否有内置的 JSON 序列化器/反序列化器?
.NET 4 是否附带任何可以序列化/反序列化 JSON 数据的类?
Does .NET 4 come with any class that serializes/deserializes JSON data?
I know there are 3rd-party libraries, such as JSON.NET, but I am looking for something built right into .NET.
I found Data Contracts on MSDN, but it is for WCF, not for Winforms or WPF.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在任何地方使用 DataContractJsonSerializer 类你想要的,它只是一个.net类,并不限于WCF。有关如何使用它的更多信息,请访问此处和此处。
You can use the DataContractJsonSerializer class anywhere you want, it is just a .net class and is not limited to WCF. More info on how to use it here and here.
有 JavaScriptSerializer 类(尽管您需要引用 System.Web.Extensions 程序集(该类在 WinForms/WPF 应用程序中工作得很好)。此外,即使 DataContractJsonSerializer 类是专为 WCF 设计,它在客户端应用程序中运行良好。
There's the JavaScriptSerializer class (although you will need to reference the
System.Web.Extensions
assembly the class works perfectly fine in WinForms/WPF applications). Also even if the DataContractJsonSerializer class was designed for WCF it works fine in client applications.使用此通用类来序列化/反序列化 JSON。
您可以轻松序列化复杂的数据结构,如下所示:
到 JSON 字符串,然后将其保存在应用程序设置中或其他
Use this generic class in order to serialize / deserialize JSON.
You can easy serialize complex data structure like this:
to JSON string and then to save it in application setting or else
.NET4有一个内置的JSON类,例如 DataContractJsonSerializer ,但它很弱,它不支持多维数组。我建议你使用 JSON.Net
.NET4 has a built-in JSON Class,such as DataContractJsonSerializer ,but it is very weak,it doesn't support multidimentional array. I suggest you use JSON.Net