JSON到DataTable

Joh*_*sen 2 c# json

我正在尝试将JSON文本序列化为DataTable,如下所示.

List<Dictionary<string, string>> list = 
JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(jsonText);
DataTable dTable;
dTable = (from p in list select p).CopyToDataTable();
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.我如何解决它?

错误:

Cannot deserialize JSON object into type 
'System.Collections.Generic.List`1[System.Collections.Generic.Dictionary`2
[System.String,System.String]]'.
Run Code Online (Sandbox Code Playgroud)

Aar*_*her 6

这对我有用:

using Newtonsoft.Json;

string json = "[{"clientID":"1788","projectID":"19"},{"clientID":"1789","projectID":"24"},{"clientID":"1790","projectID":"24"},{"clientID":"1790","projectID":"23"},{"clientID":"1790","projectID":"21"}]";

DataTable tester = (DataTable) JsonConvert.DeserializeObject(json, (typeof(DataTable)));
Run Code Online (Sandbox Code Playgroud)