Utf8JsonReader.CopyString Method

Definition

Overloads

CopyString(Span<Byte>)

Copies the current JSON token value from the source, unescaped, as UTF-8 bytes to a buffer.

CopyString(Span<Char>)

Copies the current JSON token value from the source, unescaped, as UTF-16 characters to a buffer.

CopyString(Span<Byte>)

Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs

Copies the current JSON token value from the source, unescaped, as UTF-8 bytes to a buffer.

C#
public readonly int CopyString(Span<byte> utf8Destination);

Parameters

utf8Destination
Span<Byte>

A buffer to write the unescaped UTF-8 bytes into.

Returns

The number of bytes written to utf8Destination.

Exceptions

The JSON token is not a string, that is, it's not String or PropertyName.

-or-

The JSON string contains invalid UTF-8 bytes or invalid UTF-16 surrogates.

The destination buffer is too small to hold the unescaped value.

Remarks

Unlike GetString(), this method does not support Null.

This method will throw an ArgumentException if the destination buffer is too small to hold the unescaped value. You can determine an appropriately sized buffer by consulting the length of either ValueSpan or ValueSequence, since the unescaped result is always less than or equal to the length of the encoded strings.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

CopyString(Span<Char>)

Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs
Source:
Utf8JsonReader.TryGet.cs

Copies the current JSON token value from the source, unescaped, as UTF-16 characters to a buffer.

C#
public readonly int CopyString(Span<char> destination);

Parameters

destination
Span<Char>

A buffer to write the transcoded UTF-16 characters into.

Returns

The number of characters written to destination.

Exceptions

The JSON token is not a string, that is, it's not String or PropertyName.

-or-

The JSON string contains invalid UTF-8 bytes or invalid UTF-16 surrogates.

The destination buffer is too small to hold the unescaped value.

Remarks

Unlike GetString(), this method does not support Null.

This method will throw an ArgumentException if the destination buffer is too small to hold the unescaped value. You can determine an appropriately sized buffer by consulting the length of either ValueSpan or ValueSequence, since the unescaped result is always less than or equal to the length of the encoded strings.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET 7, 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)