1
我有一个json字符串,并且想从中创建一个DataTable。我该如何将JSON转换为使用C#的数据表
如何将JSON转换为C#中的DataTable?
更新:
我已经使用Json.Net按照这里提供
,并建立2类来处理JSON字符串的链接按以下
public class JsonHelper
{
public List<User> userdata { get; set; }
}
public class User
{
public string name { get; set; }
public string id { get; set; }
public DateTime createdDate { get; set; }
}
和使用下面的代码以反序列化
Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();
json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
json.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
StringReader sr = new StringReader(jsonstr);
Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr);
object result = json.Deserialize(reader, typeof(JsonHelper));
reader.Close();
return result;
但出现以下错误
无法将JSON数组反序列化为类型'mynamespace + JsonHelper'。
这里应该是什么问题,请帮我解决这个问题。
谢谢。
我试图使用这个,但得到错误,请参阅我更新的问题。 –