In my C# code, I'm trying to deserialize a JSON with 100s of properties (complex, primitive, derived) and I'm getting an error Cannot convert null to a value type.
Though I finally knew which property is causing a problem by manual troubleshooting.
But is there any way by which I can simply know the JSON or Result_TYPE property or properties
( in one go), causing the issue ?
I tried looking into detail window
of Exception but I could only know the datatype
. In my case, it was null
trying to convert to boolean
., but not found the property name.
For example: My JSON
{
"customerData":
{
//... other json data
"someClass":{
"someClassProp1":"prop1Value",
"someClassProp2":"prop2Value"
},
"isExistData":null,
"someOtherClass":null
//... some other json data
}
}
and Result_TYPE is :
Public class CustomerData
{
// Other properties
public SomeClass someClass:
public bool isExistData;
public SomeOtherClass someOtherClass:
// some Other properties
}
I'm using
JavaScriptSerializer().Deserialize<T>(jsonString);
In above example: How would I know that property isExistData
will lead the deserialization error, because property type is boolean
and incoming data is null
. [ofcourse apart from manual debugging as there might be 100s of properties]
anyone, if knows the better way to locate the exact property?
isExistData
is a value type that can't be null... – MingJavaScriptSerializer
or any other, I could locate the problematic property at run time ? – Straus