Home >Backend Development >C++ >How to Convert a JSON String to a C# DataTable?

How to Convert a JSON String to a C# DataTable?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-26 20:56:08915browse

How to Convert a JSON String to a C# DataTable?

Convert json strings to C# datatable

Question:

Convert the JSON string that indicates the data table to C# Datatable. Original JSON structure:

The expected datata output:

<code class="language-json">[
    {"id":"10","name":"User","add":false,"edit":true,"authorize":true,"view":true},
    {"id":"11","name":"Group","add":true,"edit":false,"authorize":false,"view":true},
    {"id":"12","name":"Permission","add":true,"edit":true,"authorize":true,"view":true}
]</code>

Simplified solutions:

<code>---------------------------------------------------------------------
ID    |  Name     |  Add    |   Edit  | View   | Authorize
---------------------------------------------------------------------
10    | User      | false    |  true   | true   |  true
11    | Group     | true    |  false   | true   |  false
12    | Permission| true    |  true   | true   |  true</code>
Compared to serialization of JSON to C#class, and then converting it into DataTable, there is a more direct method. You can use json.net to directly convert:

The above is the detailed content of How to Convert a JSON String to a C# DataTable?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn