Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Apr 15, 2023 · 1 comment · Fixed by #35489
Assignees
Labels
dotnet-fundamentals/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@konrad-jamrozik
Copy link
Contributor

konrad-jamrozik commented Apr 15, 2023

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

@dotnet-bot dotnet-bot added ⌚ Not Triaged Not triaged labels Apr 15, 2023
@gewarren gewarren self-assigned this May 18, 2023
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label May 18, 2023
@ghost ghost added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label May 18, 2023
@gewarren gewarren added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label May 22, 2023
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels May 23, 2023
@gewarren gewarren moved this from 🔖 Ready to 🏗 In progress in dotnet/docs May 2023 sprint May 24, 2023
@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label May 24, 2023
@gewarren gewarren moved this from 🏗 In progress to 👀 In review in dotnet/docs May 2023 sprint May 25, 2023
@gewarren
Copy link
Contributor

That was sloppy of me - thanks for pointing this out @konrad-jamrozik. The fix will be live tomorrow.

@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in dotnet/docs May 2023 sprint May 25, 2023
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-fundamentals/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants