Why won't JsonConvert deserialize this object?

I have this JSON:

{  
    "CutCenterId":1,
    "Name":"Demo Cut Center",
    "Description":"Test",
    "IsAvailable":true,
    "E2CustomerId":"110000",
    "NumberOfMachines":2,
    "Machines":[]
}

I have the following 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; }
}

I try the following line of code where jsonJSON is installed above, and _cutCenteris a member variable.

_cutCenter = JsonConvert.DeserializeObject<CutCenter>(json);

After that _cutCenter, it is set for all default values. What for? What am I doing wrong?

+4
source share
1 answer

Your members are closed. Try it.

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; }
}
+11
source

All Articles