JSON转DataTable我正在尝试将JSON文本序列化为DataTable,如下所示。List>(jsonText);数据表dTable;dTable=(frompinlistselectp).CopyToDataTable();我收到以下错误。我该如何解决?错误:无法将JSON对象反序列化为类型“System.Collections.Generic.List`1[System.Collections.Generic.Dictionary`2[System.String,System.String]]”。这对我有用:以上是C#学习教程:从JSON到DataTable分享的所有内容,如果对你有用,需要进一步了解C#学习教程,希望大家多多关注——usingNewtonsoft.Json;stringjson="[{"clientID":"1788","projectID":"19"},{"clientID":"1789","projectID":"24"},{"clientID":"1790","projectID":"24"},{"clientID":"1790","projectID":"23"},{"clientID":"1790","projectID":"21"}]";DataTable测试器=(DataTable)JsonConvert。DeserializeObject(json,(typeof(DataTable)));publicobjectDeserialize(stringjsonText,TypevalueType){try{Newtonsoft.Json.JsonSerializerjson=newNewtonsoft.Json.JsonSerializer();json.NullValueHandling=Newtonsoft.Json.NullValueHandling.Ignore;json.ObjectCreationHandling=Newtonsoft.Json.ObjectCreationHandling.Replace;json.MissingMemberHandling=Newtonsoft.Json.MissingMemberHandling.Ignore;json.ReferenceLoopHandling=新建tonsoft.Json.ReferenceLoopHandling.Ignore;StringReadersr=newStringReader(jsonText);Newtonsoft.Json.JsonTextReaderreader=newJsonTextReader(sr);objectresult=json.Deserialize(reader,valueType);读者。关闭();;}catch(Exceptionex){抛出ex;}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
