Q:

Why does JSON serialization return a partially deserialized object?

I have this method:
public Specification RequestUnit(string jsonString)
{
    var obj = JsonConvert.DeserializeObject<SkuModel>(jsonString.Replace("on", "1"));
    return inteService.RequestSpecification(obj);
}

And, this is my JSON and is exactly what is contained in jsonString
{
"RequestStatus":"on",
"IsActive":"on",
"Code":"g87",
"Name":"fg8907",
"UnitDescription":"8gf"
}

Unfortunately, and for some unknown reason, the obj variable is only partially set. All parameters except for UnitDescription (which remains null) are successfully deserialized. I am using the Newtonsoft.Json JsonConvert class.
Anybody?

A:

The cause of this problem is this:
jsonString.Replace("on", "1")

Replace() method will replace every occurence of "on". So, your actual JSON will be like this:
{
    "RequestStatus":"1",
    "IsActive":"1",
    "Code":"g87",
    "Name":"fg8907",
    "UnitDescripti1":"8gf"
}

Note UnitDescripti1 name.
The workaround will be using 
jsonString.Replace("\"on\"", "\"1\"")

But it's better to configure you deserialization process or use custom JsonConverter, as you can get the same issue again.

