I am getting 'Error converting value' when I try to use deserilizeobject. My client sometimes sends data with quotes and special characters in it. It works when they try to serialize it. But it doesn't work when I try to deserilize it. I tried with escapehtml but still I have the same issue. It looks like 'SerializeObject' is not throwing error message that means it's valid JSON. Please let me know how to solve this issue.
string json2 = @"{
'RootObject1':{
't_date': '03-JAN-2016',
't_summary': 'test """"""""""""'
}
}";
var json3 = JsonConvert.SerializeObject(json2, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.JsonSerializerSettings{ StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml });
var myJsonObject = JsonConvert.DeserializeObject<RootObject1>(json3);
class RootObject1
{
public string t_date { get; set; }
public string t_summary { get; set; }
}
RootObjectclass's codejson3, so that's not going to deserialize to an object, only a string.json2is just a string, if you want a string as a json object, you have toparse()it first, then you can use it as a json object, anddeserialize()it into a .net object