I have a XML which I am converting to JSON and finally into C# Object.
Below is the XML
<State Description="Georgia">GA</State>
which converts to Json as
"State": { "@Description": "Georgia", "#text": "GA" }
But if the XML is <State>GA</State>
then it is "State" : "GA"
Now the problem I am facing is to write the type while deserializing.
If I declare State as String it works for <State>GA</State> condition.
[JsonProperty("State")] public string State { get; set; }
for <State Description="Georgia">GA</State> the below declaration works. But how can I declare so that it works for both the condition , Since the Description is optional we may or may not get the value.
public State State { get; set; }
public partial class State
{
[JsonProperty("#text")]
public string Text { get; set; }
[JsonProperty("@Description")]
public string Description { get; set; }
}