JSON来的DataTable [英] JSON to DataTable

查看:162
本文介绍了JSON来的DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想序列化JSON文本数据表,如以下

 列表<字典<字符串,字符串> >名单= 
JsonConvert.DeserializeObject<名单,LT;字典<字符串,字符串>>>(jsonText);
的DataTable dTable;
dTable =(从列表P选择P).CopyToDataTable();



我碰到下面的错误。我该如何解决这个问题。



错误:



 无法反序列化JSON对象入式
'System.Collections.Generic.List`1 [System.Collections.Generic.Dictionary`2
[System.String,System.String]'。


解决方案

这对我的作品:

 使用Newtonsoft.Json; 

字符串JSON =[{clientID的:1788,专案编号:19},{clientID的:1789,专案编号:24},{ clientID的:1790,专案编号:24},{clientID的:1790,专案编号:23},{clientID的:1790,专案编号:21 }];

DataTable的测试仪=(数据表)JsonConvert.DeserializeObject(JSON(typeof运算(数据表)));


I am trying to serialize JSON text to DataTable, as in the following.

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

I get the following error. How do I fix it?

ERROR :

Cannot deserialize JSON object into type 
'System.Collections.Generic.List`1[System.Collections.Generic.Dictionary`2
[System.String,System.String]]'.

解决方案

This works for me:

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)));

这篇关于JSON来的DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆