-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Type of issue
Other (describe below)
Description
The examples show how to serialize a complex object, but they do not show how to deserialize it. They only show that the root object is deserialized. I suggest adding code like the following to show that the child objects are also deserialized:
if (weatherForecast != null)
{
if (weatherForecast.DatesAvailable != null)
{
foreach (DateTimeOffset dateTimeOffset in weatherForecast.DatesAvailable)
{
Console.WriteLine(value: $"DateAvailable: {dateTimeOffset}");
}
}
if (weatherForecast.TemperatureRanges != null)
{
foreach (KeyValuePair<string, HighLowTemps> weatherForecastTemperatureRange in weatherForecast.TemperatureRanges)
{
Console.WriteLine(value: $"TemperatureRange: {weatherForecastTemperatureRange.Key}, {weatherForecastTemperatureRange.Value.Low} - {weatherForecastTemperatureRange.Value.High}");
}
}
if (weatherForecast.SummaryWords != null)
{
foreach (string summaryWord in weatherForecast.SummaryWords)
{
Console.WriteLine(value: $"SummaryWord: {summaryWord}");
}
}
}
Output would then be:
Date: 8/1/2019 12:00:00 AM +02:00
TemperatureCelsius: 25
Summary: Hot
DateAvailable: 8/1/2019 12:00:00 AM +02:00
DateAvailable: 8/2/2019 12:00:00 AM +02:00
TemperatureRange: Cold, -10 - 20
TemperatureRange: Hot, 20 - 60
SummaryWord: Cool
SummaryWord: Windy
SummaryWord: Humid
It would also be extremely helpful to have an example on how to deserialize interfaces. E.g. like at https://gist.github.com/tonysneed/5e7988516b081d454cde95b5d729e1af
Page URL
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/how-to
Content source URL
Document Version Independent Id
002f9f2a-48d1-0671-a079-b99b9f6bab58
Article author
gewarren
Metadata
- ID: 588ae32f-3429-143f-824c-5ab2d046d24a
- Service: dotnet-fundamentals
Metadata
Metadata
Labels
Type
Projects
Status