Horje
system.text.json DeserializeAsync when to use Code Example
system.text.json DeserializeAsync when to use
/// <Summary>
/// You should used JsonSerializer when you:
///
/// Have a POCO that matches the JSON data, or it’s easy to create one.
/// Need to use most of the properties of the JSON in your application code.
/// </Summary
  
var data = await JsonSerializer.DeserializeAsync<SomeObject>(req.Body);

// It’s much neater to deserialize the request body this way, and it avoids the unnecessary string allocation, since the serializer consumes the stream for you.

// The Deserialize method can also take a ReadOnlySpan of bytes as input. Much like the stream example above, you previously had to read the bytes into a string before deserializing it to JSON. Instead, if you’ve already got the data loaded in memory, this overload saves you a few allocations and parses the JSON directly into a POCO.

// It’s also worth nothing that some of the default options for System.Text.Json are different from Json.NET. System.Text.Json adheres to RFC 8259, so if you’re ever left wondering why a setting is different from Newtonsoft, that’s probably why.




Csharp

Related
unity c# addition class Code Example unity c# addition class Code Example
c# list slice Code Example c# list slice Code Example
unity c# class addition syntax Code Example unity c# class addition syntax Code Example
unity how to end a game with esc Code Example unity how to end a game with esc Code Example
byte to stream c# Code Example byte to stream c# Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10