Deserialize Json in C# - How to Handle null Return Values
Try to use nullable type
public string? name;
How to handle null/empty values in JsonConvert.DeserializeObject
You can supply settings to JsonConvert.DeserializeObject
to tell it how to handle null values, in this case, and much more:
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};
var jsonModel = JsonConvert.DeserializeObject<Customer>(jsonString, settings);
Need to ignore NULL values when deserializing JSON
NullValueHandling.Ignore
will ignore null values for the relevant property of your model when serializing.
When deserialzing, you might consider deserializing to an IEnumerable<ChartData>
then using Linq to filter out the objects you don't want, based on what is, after all, custom logic: "exclude objects that have close == null".
E.g. (untested air code):
var data = JsonConvert.DeserializeObject<IEnumerable<ChartData>>(content,jsonSettings)
.Where(cd => cd.close != null)
;
var observableData = new ObservableCollection<ChartData>(data);
Related Topics
Create a C# Method to Generate Auto Increment Id
How to Calculate Sum (Total) of Datatable Columns Using C#
Load Image from Resources Area of Project in C#
How to Remove Empty Lines from a Formatted String
How to Remove Carriage Returns from the Json Output of My Webapi Service
How to Count Number of Visitors for Website in ASP.NET C#
How to Refresh or Show Immediately in Datagridview After Inserting
Check If Task Is Already Running Before Starting New
How to Convert a String Containing Am/Pm to Datetime
Unexpected Character Encountered While Parsing Value
Regular Expression for Password Validation in C#
Asp.Net Core Form Post Results in a Http 415 Unsupported Media Type Response
How to Download a File from a Url in C#
How to Add/Update Child Entities When Updating a Parent Entity in Ef
Split a Comma-Separated String With Both Quoted and Unquoted Strings