C# 为什么赢了';JSONVERT是否反序列化此对象?
我有一个JSON:C# 为什么赢了';JSONVERT是否反序列化此对象?,c#,json,C#,Json,我有一个JSON: { "CutCenterId":1, "Name":"Demo Cut Center", "Description":"Test", "IsAvailable":true, "E2CustomerId":"110000", "NumberOfMachines":2, "Machines":[] } 我有以下POCO: public class CutCenter { int CutCenterId { ge
{
"CutCenterId":1,
"Name":"Demo Cut Center",
"Description":"Test",
"IsAvailable":true,
"E2CustomerId":"110000",
"NumberOfMachines":2,
"Machines":[]
}
我有以下POCO:
public class CutCenter
{
int CutCenterId { get; set; }
string Name { get; set; }
string Description { get; set; }
bool IsAvailable { get; set; }
string E2CustomerId { get; set; }
int NumberOfMachines { get; set; }
}
我尝试以下代码行,其中json
设置为上述json,并且\u cutCenter
是一个成员变量
_cutCenter = JsonConvert.DeserializeObject<CutCenter>(json);
\u cutCenter=JsonConvert.DeserializeObject(json);
在此之后,
\u剪切中心
设置为所有默认值。为什么?我做错了什么?您的会员都是私人会员。试试这个
public class CutCenter
{
public int CutCenterId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsAvailable { get; set; }
public string E2CustomerId { get; set; }
public int NumberOfMachines { get; set; }
}
您的“机器”不是类的属性。您确定JSON有效吗。它看起来好像丢失了
[
和]
-相信我,这些小东西可能是你生活中的祸根。@ppumpkin,根据jsonformatter.curiousconcept.com,它是有效的。[]是一个空数组。若要验证JSON,请首先在.NET中填充类,然后将其序列化,并将其与现有的进行比较。您需要创建一个类,该类的公共字段或属性与JSON字符串上的字段名相匹配