Skip to content

Instantly share code, notes, and snippets.

@lucamauri
Created August 14, 2020 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucamauri/4b491b195f2ef12566d6bd62b40514a3 to your computer and use it in GitHub Desktop.
Save lucamauri/4b491b195f2ef12566d6bd62b40514a3 to your computer and use it in GitHub Desktop.
VB.net examples with System.Text.Json
Dim Options = New JsonWriterOptions
With options
.Indented = True
End With
Dim MemStream As New MemoryStream
Dim Writer As New Utf8JsonWriter(MemStream, Options)
Writer.WriteStartObject()
Writer.WriteString("date", DateTimeOffset.UtcNow)
Writer.WriteNumber("temp", 42)
Writer.WriteEndObject()
Console.WriteLine(Writer.BytesPending)
Writer.Flush()
Console.WriteLine(MemStream.Length)
MemStream.Close()
Dim JSON As String = Encoding.UTF8.GetString(MemStream.ToArray())
Console.WriteLine(Json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment