Skip to content

Code snippet in Consume decoded JSON strings in How to use a JSON document, Utf8JsonReader, and Utf8JsonWriter in System.Text.Json does not compile #35019

Closed
@konrad-jamrozik

Description

@konrad-jamrozik

I copy-pasted the code snippet from Consume decoded JSON strings section into my Visual Studio:

int valueLength = reader.HasReadOnlySequence 
    ? checked((int)ValueSequence.Length) 
    : ValueSpan.Length;

char[] buffer = ArrayPool<char>.Shared.Rent(valueLength);
int charsRead = reader.CopyString(buffer);
ReadOnlySpan<char> source = buffer.Slice(0, charsRead);

// Handle the unescaped JSON string.
ParseUnescapedString(source);
ArrayPool<char>.Shared.Return(buffer, clearArray: true);

and here is what I got:

image

all the symbols marked in red are not recognized. I searched a bit and looks like this is not a problem with my setup.

For example, Utf8JsonReader doesn't appear to have a HasReadOnlySequence member.

It is also a bit confusing that the section says:

The following code snippet shows an example of consuming a UTF-16 string using CopyString.

but refers to UTF-8. So is it UTF-8 or UTF-16 ?

I think the doc should provide near-obviously-compilable code snippets. At the very least it should explain what needs to be done to make the snippet compile, like what dependencies to import to get the right Slice method, how to implement ParseUnescapedString and so on.

Related:


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 91665

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.dotnet-fundamentals/svcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions