--- lang: ja-jp breaks: true --- # System.Text.Json Json 文字列を見やすく整形する。 2022-08-02 ```csharp! string json; using (var stream = new MemoryStream()) { JsonWriterOptions jsonWriterOptions = new() { Indented = true, SkipValidation = true, Encoder = JavaScriptEncoder.Create(UnicodeRanges.All), }; using (Utf8JsonWriter writer = new Utf8JsonWriter(stream, jsonWriterOptions)) { using (JsonDocument jsonDocument = JsonDocument.Parse(jsonString)) { jsonDocument.WriteTo(writer); writer.Flush(); } json = Encoding.UTF8.GetString(stream.ToArray()); } } Debug.WriteLine("------------------------"); Debug.WriteLine(json); Debug.WriteLine("------------------------"); ``` ###### tags: `System.Text.Json`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up