Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用newtonsoft反序列化为json字符串_C#_Json.net - Fatal编程技术网

C# 无法使用newtonsoft反序列化为json字符串

C# 无法使用newtonsoft反序列化为json字符串,c#,json.net,C#,Json.net,执行此命令时,JSON字符串的重复部分未被反序列化: UsageAndDemand.UsageAndDemandResponse UsgDmdResp = JsonConvert.DeserializeObject<UsageAndDemand.UsageAndDemandResponse>(jsonString); 通过VS2015中的调试器,如果我检查反序列化对象(UsgDmdResp),我可以看到ResponseCode等于0,消息显示“success”,但重复部分(JSON

执行此命令时,JSON字符串的重复部分未被反序列化:

UsageAndDemand.UsageAndDemandResponse UsgDmdResp = JsonConvert.DeserializeObject<UsageAndDemand.UsageAndDemandResponse>(jsonString);
通过VS2015中的调试器,如果我检查反序列化对象(UsgDmdResp),我可以看到
ResponseCode
等于0,消息显示“success”,但重复部分(JSON字符串)为null。正如我前面提到的,这段代码正在另一个反序列化到稍微不同的对象类的页面中工作


有人能看到我的重复值为空的原因吗?

错误的属性名称
MeterUsageDemand
应该是
UsageAndDemand

public class UsageAndDemandResponse
{
    public int ResponseCode { get; set; }
    public string Message { get; set; }
    [JsonProperty("UsageAndDemand", NullValueHandling = NullValueHandling.Ignore)]
    public List<MeterUsageDemand> MeterUsageDemand { get; set; }
}
公共类用法和需求响应
{
公共int响应代码{get;set;}
公共字符串消息{get;set;}
[JsonProperty(“UsageAndDemand”,NullValueHandling=NullValueHandling.Ignore)]
公共列表MeterSageDemand{get;set;}
}

公共类用法和需求响应
{
公共int响应代码{get;set;}
公共字符串消息{get;set;}
公共列表UsageAndDemand{get;set;}
}

错误的属性名称
MeterUsageDemand
UsageAndDemand

public class UsageAndDemandResponse
{
    public int ResponseCode { get; set; }
    public string Message { get; set; }
    [JsonProperty("UsageAndDemand", NullValueHandling = NullValueHandling.Ignore)]
    public List<MeterUsageDemand> MeterUsageDemand { get; set; }
}
公共类用法和需求响应
{
公共int响应代码{get;set;}
公共字符串消息{get;set;}
[JsonProperty(“UsageAndDemand”,NullValueHandling=NullValueHandling.Ignore)]
公共列表MeterSageDemand{get;set;}
}

公共类用法和需求响应
{
公共int响应代码{get;set;}
公共字符串消息{get;set;}
公共列表UsageAndDemand{get;set;}
}

UsageAndDemand
在JSON中与
MeterUsageDemand
在您的C#类中不匹配
UsageAndDemand
在JSON中与
MeterUsageDemand
在您的C#类中不匹配嘿,非常感谢您的回答。我说的那个在另一个页面中使用另一个类…我想我只是幸运地得到了我的属性名。再次感谢。嘿,伙计们,非常感谢你们的回答。我说的那个在另一个页面中使用另一个类…我想我只是幸运地得到了我的属性名。再次感谢。
{
"ResponseCode" : 0,
"Message" : "Success",
"UsageAndDemand" : [
{
  "UsageDate" : "2018-08-01",
  "KwhUsed" : 624.27,
  "HighTemp" : 93.00,
  "LowTemp" : 70.00,
  "KwDemand" : 1.21
},
{
  "UsageDate" : "2018-09-01",
  "KwhUsed" : 777.75,
  "HighTemp" : 93.00,
  "LowTemp" : 68.00,
  "KwDemand" : 1.12
},
{
  "UsageDate" : "2018-10-01",
  "KwhUsed" : 815.52,
  "HighTemp" : 91.00,
  "LowTemp" : 50.00,
  "KwDemand" : 1.28
},
{
  "UsageDate" : "2018-11-01",
  "KwhUsed" : 844.68,
  "HighTemp" : 87.00,
  "LowTemp" : 36.00,
  "KwDemand" : 1.3
},
{
  "UsageDate" : "2018-12-01",
  "KwhUsed" : 800.8,
  "HighTemp" : 81.00,
  "LowTemp" : 41.00,
  "KwDemand" : 1.27
},
{
  "UsageDate" : "2019-01-01",
  "KwhUsed" : 27.8,
  "KwDemand" : 1.22
}
]
}
public class UsageAndDemandResponse
{
    public int ResponseCode { get; set; }
    public string Message { get; set; }
    [JsonProperty("UsageAndDemand", NullValueHandling = NullValueHandling.Ignore)]
    public List<MeterUsageDemand> MeterUsageDemand { get; set; }
}
public class UsageAndDemandResponse
{
    public int ResponseCode { get; set; }
    public string Message { get; set; }
    public List<MeterUsageDemand> UsageAndDemand{ get; set; }
}