A bit stuck, (confusing myself really, I think).
I am wanting to convert a value from a JSON string from it String representation of hex to an int. I only need to get the value I will never need to write the other way.
For instance
{
"name" : "someName",
"id" : "b1"
}
I have a class created
public class Person
{
public string name;
[JsonConverter(typeof(myConverter))]
public int id;
}
and my converter (I am not sure I understand this part correctly)
public class myConverter : JsonConverter
{
//CanConvert Boiler Plate
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
string sValue = existingValue.ToString().ToUpper();
int iValue = Convert.ToInt32(sValue);
return iValue;
}
I will of course add additional checks to validate data and what not, but I wanted to start with something to see how it worked.
So with the above example I would want my int to be 177
Any help, guidance would be appreciated.