I am receiving the following Json string as output from a REST service:
"CategoryDtls":
{
"category": "S",
"msgType": "0",
"sourceId": "21999"
}
I wish to convert it to a C# object using Json.net
public partial class CategoryDtls
{
private TestChar categoryField;
public TestChar category
{
get
{
return categoryField;
}
set
{
if (value == null)
{
categoryField = null;
}
var stringValue = Convert.ToString(value);
var charClass = new TestChar();
charClass.SimpleChar = stringValue;
categoryField = charClass;
}
}
public string msgType { get; set; }
public string sourceId { get; set; }
}
public partial class TestChar : object, System.ComponentModel.INotifyPropertyChanged
{
private string simpleCharField;
public string SimpleChar
{
get
{
return this.simpleCharField;
}
set
{
this.simpleCharField = value;
this.RaisePropertyChanged("SimpleChar");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null))
{
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
When doing so, I get an error like
{"Could not cast or convert from System.String to JsonParser.TestChar."}
I tried to customize the set method for Category property like above but couldn't resolve it. I can't change the Json string. Is there anyway, I can resolve this issue.