我有以下json,我正在尝试反序列化以将其插入到SQL表中,我已经尝试使用JsonConvert和JObject,但没有得到积极的结果。
Json
{
"id": "123123",
"publisherId": "Empresa",
"notificationType": "Orden",
"headers": {
"providerId": "ABC123"
},
"content": {
"id": "987987",
"orderId": "4444444",
"apiName": "Services",
"method": "GetOrder",
"verb": "GET",
"urlMethod": "https://api.com"
},
"contentVersion": "1.0"
}模型
public class Headers
{
public string providerId { get; set; }
}
public class Content
{
public string id { get; set; }
public string orderId { get; set; }
public string apiName { get; set; }
public string method { get; set; }
public string verb { get; set; }
public string urlMethod { get; set; }
}
public class RootModel
{
public string id { get; set; }
public string publisherId { get; set; }
public string notificationType { get; set; }
public Headers headers { get; set; }
public Content content { get; set; }
public string contentVersion { get; set; }
}代码
public static List<Models.RootModel> getJson()
{
using (StreamReader r = new StreamReader("c:\\LOG\\20180528\\201805281039.json"))
{
string json = r.ReadToEnd();
return JsonConvert.DeserializeObject<Models.RootModel>(json);
}
}您给了我以下错误
Error CS0029 No se puede implícitamente el tipo 'WebApplication1.Models.RootModel‘en 'System.Collections.Generic.List’
我真的不知道我是否在正确的轨道上,是否有必要反序列化才能在DB中插入,或者是否有其他方法?
提前感谢你的帮助
https://stackoverflow.com/questions/50565658
复制相似问题