Hi Khushisshaikh,
I did some research about System.Text.Json and found that System.Text.Json has more restrictions.
For example, there is currently no built-in support for types like DataSet and DataTable in System.Text.Json.
And the official document says, there may be solutions for unsupported functions. The solution is to customize converters, they may not provide exactly the same functions as Newtonsoft.Json.
More details you can refer to this document.
So if you want to deserialize json to datatable, Newtonsoft.Json is a good choice.
Here is a code example you can refer to.17589-example.txt
Best Regards,
Daniel Zhang
Does System.Text.Json Deserialize into DataTable?
Khushi Shaikh
86
Reputation points
Hello .Net Gurus - I have checked MS Documentation and I couldn't find any example of serialize json data using System.Text.JSON into DataTable. I have .Net Framwork 4.7.2 and did install the System.Text.Json NuGet package. The desrialization is working perfectly using NewtonSoft's JSON. I prefer to use Microsoft's libraries. Any guidance is much appreciated.
//Calling Code
dt = JsonSerializer.Deserialize<DataTable>(apiResponse, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
PS: While goggling I came across the post where a comment was "System.Text.JSON" doesn't support deserialize into DataTable. Is this true?
Thanks & Regards,
Khushi
Accepted answer
-
Daniel Zhang-MSFT 9,626 Reputation points
2020-08-14T07:53:29.587+00:00