我有这个 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 并且 _cutCenter
是一个成员变量。
_cutCenter = JsonConvert.DeserializeObject<CutCenter>(json);
此后 _cutCenter
设置为所有默认值。为什么?我做错了什么?
最佳答案
您的成员都是私有(private)的。试试这个。
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; }
}
关于c# - 为什么 JsonConvert 不反序列化这个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29393676/