Utf8JsonReader.ValueSpan 属性

定义

如果令牌适合单个段,或者如果读取器是使用 ReadOnlySpan<byte> 中包含的 JSON 有效负载构造的,则获取上次处理的令牌的原始值作为输入有效负载的 ReadOnlySpan<byte> 切片。Gets the raw value of the last processed token as a ReadOnlySpan<byte> slice of the input payload, if the token fits in a single segment or if the reader was constructed with a JSON payload contained in a ReadOnlySpan<byte>.

public:
 property ReadOnlySpan<System::Byte> ValueSpan { ReadOnlySpan<System::Byte> get(); };
public ReadOnlySpan<byte> ValueSpan { get; }
member this.ValueSpan : ReadOnlySpan<byte>
Public ReadOnly Property ValueSpan As ReadOnlySpan(Of Byte)

属性值

ReadOnlySpan<Byte>

字节的只读范围。A read-only span of bytes.

注解

如果在 ReadOnlySequence<byte> 内提供 JSON,并且表示令牌值的切片适合单个段,则 ValueSpan 包含切分的值,因为它可以表示为一个范围。If the JSON is provided within a ReadOnlySequence<byte> and the slice that represents the token value fits in a single segment, then ValueSpan contains the sliced value since it can be represented as a span. 否则 ValueSequence 包含令牌值。Otherwise, ValueSequence contains the token value.

如果 HasValueSequencetrueValueSpan 则为空。If HasValueSequence is true, ValueSpan is empty. 因此,仅 ValueSpan 当为时才访问 HasValueSequence falseTherefore, only access ValueSpan if HasValueSequence is false. 否则,必须从访问令牌值 ValueSequenceOtherwise, the token value must be accessed from ValueSequence.

不保证此属性将始终包含格式正确的数据。There is no guarantee that this property will always contain well-formed data. 如果传入的输入 JSON Utf8JsonReader 包含 json 字符串标记中的无效 utf-8 字节,则此属性将返回这些无效的 utf-8 字节。If the input JSON passed in to the Utf8JsonReader contains invalid UTF-8 bytes within JSON string tokens, this property will return back those invalid UTF-8 bytes as is. 因此,如果输入不受信任或未经验证,则调用 GetString() 以获取 JSON 字符串标记。Therefore, if the input is untrusted or not previously validated, call GetString() to get the JSON string token.

由于此属性返回原始字节,因此应避免将其用于文本比较。Since this property returns the raw bytes, avoid using it for text comparison. 如果需要,请改 ValueTextEquals 为调用 unescapes 文本。Instead call ValueTextEquals which unescapes the text if necessary.

适用于