I have a json string like {field:'DateToEnd',dir:'asc'}
And i have a class in c# with following two properties.
public class SortDescriptor
{
public SortDescriptor()
{
}
public string Field { get; set; }
public string Dir { get; set; }
}
Now i want to convert this string to the class object so that i can access the properties.
I tried the following example. But it's not working for me.
JavaScriptSerializer serialize = new JavaScriptSerializer();
SortDescriptor sort = (SortDescriptor)serialize.DeserializeObject(fixSortString);
It gives following error:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'NF.Common.SortDescriptor'.
Can anyone let me know that how i can do this?