我想将 JSON 文件转换为 C# 类并存储在数据库中。我的代码
string json = new System.Net.WebClient().DownloadString(Path);
{
"qqq": "xxxx",
"rrrr": "xxxxx",
"abc": {
"abc1": "xxxxx",
"abc2": "xxxxx",
"abc3": "xxxxx",
"abc4": "xxxxx",
"abc5": "2018-05-28T06:10:00.000"
},
"xyx": {
"xyz1": "xxxxx",
"xyz2": "xxxxx",
"xyz3": "xxxxx",
"xyz4": "xxxxx",
"xyz5": "2018-05-28T07:30:00.000"
}
},
{
"qqq": "xxxxx",
"rrrr": "xxxxx",
"abc": {
"abc1": "xxxxx",
"abc2": "xxxxx",
"abc3": "xxxxx",
"abc4": "xxxxx",
"abc5": "2018-05-28T06:10:00.000"
},
"xyz": {
"xyz1": "xxxxx",
"xyz2": "xxxxx",
"xyz3": "xxxxx",
"xyz4": "xxxxx",
"xyz5": "2018-05-28T07:30:00.000",
}
}
public class Rootobject
{
public string qqq { get; set; }
public string rrrr { get; set; }
public Abc abc { get; set; }
public Xyz xyz { get; set; }
}
public class Abc
{
public string abc1 { get; set; }
public string abc2 { get; set; }
public string abc3 { get; set; }
public string abc4 { get; set; }
public DateTime abc5 { get; set; }
}
public class Xyz
{
public string xyz1 { get; set; }
public string xyz2 { get; set; }
public string xyz3 { get; set; }
public string xyz4 { get; set; }
public DateTime xyz5 { get; set; }
}
Rootobject ra = new Rootobject();
ra = JsonConvert.DeserializeObject<Rootobject>(json);
我收到以下错误无法将当前 JSON 数组(例如 [1,2,3])反序列化为类型“testProject.Form1+Rootobject”,因为该类型需要一个 JSON 对象(例如 {\"name\":\"value\ "}) 以正确反序列化。\r\n要修复此错误,请将 JSON 更改为 JSON 对象
缥缈止盈
德玛西亚99
相关分类