Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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# 为什么赢了';JSONVERT是否反序列化此对象?_C#_Json - Fatal编程技术网

C# 为什么赢了';JSONVERT是否反序列化此对象?

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

我有一个JSON:

{  
    "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字符串上的字段名相匹配