I am trying to Deserialize json data which i have to with respect to model class i have
Json :
"{'test':'1339886'}"
Classes :
public class NewtonTest
{
public Element test { get; set; }
}
public class Element
{
public string sample { get; set; }
}
In Main class :
//under Main
string jsonData = "{'test':'1339886'}";
var = JsonConvert.DeserializeObject<NewtonTest>(jsonData);
Error Info : //innner exception
Could not cast or convert from System.String to Test.Element."
I am completely aware of what the error states as i am passing string
in my json
where as in class i have a class
as type(mismatch happening) .
In such cases i need to handle the error and maybe place a null if there is mismatch in output but it should not throw exception .
I tried my best reading the docs and setting options via settings but none seem to work .
I am using version 4.5 of Newtonsoft.Json