en	= Quick Look Here we highlight important features through example code to help convey the style of the interface. We begin by including the library header file which brings all the symbols into scope. Alternatively, individual headers may be included to obtain the declarations for specific types:
zh-hans	= 快速浏览 这里我们通过示例代码重点介绍重要特性，以帮助理解接口风格。首先包含库头文件，该文件将所有符号引入作用域；或者，也可以包含单独的头文件以获取特定类型的声明：

en	In order to link your program you will need to link with a built library. Alternatively you can use the header-only configuration simply by including this header file in any __one__ of your new or existing source files:
zh-hans	为链接程序，您需要链接已构建的库。或者，您可以使用仅需头文件（header-only）的配置，只需在任意__一个__新建或现有源文件中包含此头文件：

en	Values
zh-hans	值

en	Say you want to recreate this JSON object in a container:
zh-hans	假设您要在容器中重建一下 JSON 对象：

en	In this library the types <<ref_array>>, <<ref_object>>, and <<ref_string>> hold JSON arrays, objects, and strings respectively while the type <<ref_value>> is a special variant which can hold any JSON element. Here we construct an empty object and then insert the elements above:
zh-hans	在本库中，类型 &lt;<ref_array>&gt;、&lt;<ref_object>&gt; 和 &lt;<ref_string>&gt; 分别用于表示 JSON 数组、对象和字符串，而类型 &lt;<ref_value>&gt; 是一种特殊的变体（variant），可容纳任意 JSON 元素。以下示例首先构造一个空对象，然后插入上述元素：</ref_value></ref_string></ref_object></ref_array>

en	While keys are strings, the mapped type of objects and the element type of arrays is the aforementioned type <<ref_value>> which can hold any JSON element, as seen in the previous assignments. Instead of building the JSON document using a series of function calls, we can build it in one statement using an initializer list:
zh-hans	尽管键是字符串，但对象的映射类型和数组的元素类型均为前述的 &lt;<ref_value>&gt; 类型，它可以保存任意 JSON 元素，如前文赋值所示。除了通过一系列函数调用构建 JSON 文档外，我们还可以使用初始化列表在一条语句中完成构建：</ref_value>

en	When a <<ref_value>>, <<ref_array>>, or <<ref_object>> is assigned or constructed from an initializer list, the creation of the new value happens only once. This makes initializer lists equally efficient as using the other ways to create a value. The types in this library are first-class, supporting copy and move construction and assignment:
zh-hans	当 &lt;<ref_value>&gt;, &lt;<ref_array>&gt;, 或 &lt;<ref_object>&gt; 通过初始化列表进行赋值或构造时，新值的创建仅发生一次。这使得初始化列表在效率上与其他创建值的方式相当。本库中的类型均为一等类型，支持复制和移动构造及赋值：</ref_object></ref_array></ref_value>

en	Allocators
zh-hans	分配器

en	To permit custom memory allocation strategies, these containers all allow construction with a <<ref_storage_ptr>> which is a smart pointer to a {ref_memory_resource}. The constructor signatures have the same ordering as their `std` equivalents which use {req_Allocator} parameters. Once a container is constructed its memory resource can never change. Here we create an array without performing any dynamic allocations:
zh-hans	为支持自定义内存分配策略，这些容器均允许通过一个 &lt;<ref_storage_ptr>&gt;（指向 {ref_memory_resource} 的智能指针）进行构造。其构造函数签名的参数顺序与使用 {req_Allocator} 参数的标准库等价类型一致。容器一旦构造完成，其内存资源便不可更改。以下代码创建了一个未执行任何动态分配的数组：</ref_storage_ptr>

en	The containers in this library enforce the invariant that every element of the container will use the same memory resource:
zh-hans	本库中的容器强制保持一个不变式：容器的每个元素都使用相同的内存资源：

en	When a library type is used as the element type of a PMR container; that is, a container which uses a {ref_polymorphic_allocator}, the memory resource will automatically propagate to the type and all of its children:
zh-hans	当库类型用作 PMR 容器（即使用 {ref_polymorphic_allocator} 的容器）的元素类型时，内存资源将自动传播至该类型及其所有子元素：

en	Up until now we have shown how values may be constructed from a memory resource pointer, where ownership is not transferred. In this case the caller is responsible for ensuring that the lifetime of the resource is extended for the life of the container. Sometimes you want the container to acquire shared ownership of the resource. This is accomplished with <<ref_make_shared_resource>>:
zh-hans	截至目前，我们已展示如何通过内存资源指针（不转移所有权）构造值。此时调用方需确保资源生命周期覆盖容器的生命周期。有时您希望容器获取资源的共享所有权。这可通过 &lt;<ref_make_shared_resource>&gt; 实现：</ref_make_shared_resource>

en	A counted memory resource will not be destroyed until every container with shared ownership of the resource is destroyed.
zh-hans	计数内存资源在拥有其共享所有权的每个容器均被销毁之前，是不会被销毁的。

en	Parsing
zh-hans	解析

en	JSON can be parsed into the value container in one step using a free function. In the following snippet, a parse error is indicated by a thrown exception:
zh-hans	可使用自由函数将 JSON 一步解析至值容器。在以下代码片段中，解析错误通过抛出异常指示：

en	Error codes are also possible:
zh-hans	也支持错误码：

en	By default, the parser is strict and only accepts JSON compliant with the standard. However this behavior can be relaxed by filling out an options structure enabling one or more extensions. Here we use a static buffer and enable two non-standard extensions:
zh-hans	默认情况下，解析器采用严格模式，仅接受符合标准的 JSON。但可通过填充一个选项结构体来启用一个或多个扩展，从而放宽此行为。以下示例使用静态缓冲区并启用了两个非标准扩展：

en	The parser in this library implements a https://en.wikipedia.org/wiki/Online_algorithm[__streaming algorithm__]; it can process JSON piece-by-piece, without the requirement that the entire input is available from the start. The parser uses a temporary memory allocation to do its work. If you plan on parsing multiple JSONs, for example in a network server, keeping the same parser instance will allow re-use of this temporary storage, improving performance.
zh-hans	本库中的解析器实现了一种 https://en.wikipedia.org/wiki/Online_algorithm[__streaming algorithm__]（流式算法）；它可逐段处理 JSON，无需从一开始就提供完整输入。解析器在工作时会使用临时内存分配。如果计划解析多个 JSON（例如在网络服务器中），复用同一个解析器实例可以重用该临时存储，从而提升性能。

en	With strategic use of the right memory resources, parser instance, and calculated upper limits on buffer sizes, it is possible to parse and examine JSON without __any__ dynamic memory allocations. This is explored in more detail in a later section.
zh-hans	通过合理使用适当的内存资源、解析器实例及缓冲区大小的计算上限，可在不进行__任何__动态内存分配的情况下解析和检查 JSON。后续章节将对此进行更详细探讨。

en	Serializing
zh-hans	序列化

en	Simple free functions are provided for serializing a <<ref_value>> to a {std_string} containing JSON:
zh-hans	提供了简单的自由函数，用于将 &lt;<ref_value>&gt; 序列化为包含 JSON 的 {std_string}：</ref_value>

en	The serializer in this library implements a https://en.wikipedia.org/wiki/Online_algorithm[__streaming algorithm__]; it can output JSON a piece at a time, without the requirement that the entire output area is allocated at once:
zh-hans	本库中的序列化器实现了 https://en.wikipedia.org/wiki/Online_algorithm[__streaming algorithm__]（流式算法）；它可逐段输出 JSON，无需一次性分配整个输出空间：

en	Value Conversion
zh-hans	值转换

en	Given a user-defined type:
zh-hans	给定一个用户定义的类型：

en	We can define a conversion from the user-defined type to a <<ref_value>> by defining an overload of `tag_invoke` in the same namespace. This maps `customer` to a JSON object:
zh-hans	我们可在同一命名空间中定义 `tag_invoke` 的重载，来实现从用户定义类型到 &lt;<ref_value>&gt; 的转换。此操作将 `customer` 映射为 JSON 对象：</ref_value>

en	This allows us to use the library function <<ref_value_from>> to produce a <<ref_value>> from our type:
zh-hans	这允许我们可以使用库函数 &lt;<ref_value_from>&gt; 从我们的类型生成一个 &lt;<ref_value>&gt;：</ref_value></ref_value_from>

en	The library knows what to do with standard containers. Here we convert an array of customers to a value:
zh-hans	该库能够自动处理标准容器。以下我们将一个客户数组转换为一个值：

en	To go from JSON to a user-defined type we use <<ref_value_to>>, which uses another overload of `tag_invoke`. This converts a JSON value to a `customer`. It throws an exception if the contents of the value do not match what is expected:
zh-hans	为将 JSON 转换为用户定义类型，我们使用 &lt;<ref_value_to>&gt;（它会调用 `tag_invoke` 的另一个重载）。此操作将 JSON 值转换为 `customer`。若值内容不符合预期，则抛出异常：</ref_value_to>

en	The code above defines the convenience function `extract`, which deduces the types of the struct members. This works, but requires that the struct is {req_DefaultConstructible}. An alternative is to construct the object directly, which is a little more verbose but doesn't require default construction:
zh-hans	上述代码定义了便捷函数 `extract`，它能推导结构体成员的类型。这种方式可行，但要求该结构体是 {req_DefaultConstructible}。另一种方法是直接构造对象，虽然略显冗长，但无需默认构造：

en	Now we can construct customers from JSON:
zh-hans	现在我们可以从 JSON 构造客户对象（customer）：

en	The library's generic algorithms recognize when you are converting a <<ref_value>> to a container which resembles an array or object, so if you wanted to turn a JSON array into a vector of customers you might write:
zh-hans	当将 &lt;<ref_value>&gt; 转换为类似数组或对象的容器时，库的通用算法可自动识别。因此若要将 JSON 数组转换为客户向量，可编写如下代码：</ref_value>