.NET 中的 JSON 序列化和反序列化(封送和拆收)- 概述JSON serialization and deserialization (marshalling and unmarshalling) in .NET - overview

System.Text.Json 命名空间提供用于序列化和反序列化 JavaScript 对象表示法 (JSON) 的功能。The System.Text.Json namespace provides functionality for serializing to and deserializing from JavaScript Object Notation (JSON).

库的设计强调对广泛的功能集实现高性能和低内存分配。The library design emphasizes high performance and low memory allocation over an extensive feature set. 内置的 UTF-8 支持可优化读写以 UTF-8 编码的 JSON 文本的过程,UTF-8 编码是针对 Web 上的数据和磁盘上的文件的最普遍的编码方式。Built-in UTF-8 support optimizes the process of reading and writing JSON text encoded as UTF-8, which is the most prevalent encoding for data on the web and files on disk.

库还提供了用于处理内存中文档对象模型 (DOM) 的类。The library also provides classes for working with an in-memory document object model (DOM). 此功能允许对 JSON 文件或字符串中的元素进行随机只读访问。This feature enables random read-only access of the elements in a JSON file or string.

如何获取库How to get the library

  • 该库是作为 .NET Core 3.0 及更高版本共享框架的一部分内置的。The library is built-in as part of the shared framework for .NET Core 3.0 and later versions.

  • 对于早期版本的框架,请安装 System.Text.Json NuGet 包。For earlier framework versions, install the System.Text.Json NuGet package. 包支持以下框架:The package supports:

    • .NET Standard 2.0 及更高版本.NET Standard 2.0 and later versions
    • .NET Framework 4.7.2 及更高版本.NET Framework 4.7.2 and later versions
    • .NET Core 2.0、2.1 和 2.2.NET Core 2.0, 2.1, and 2.2

其他资源Additional resources