I have the following object
public class Error
{
public long id { get; set; }
public string code { get; set; }
public string message { get; set; }
public long qty{ get; set; }
}
public class RootObject
{
public List<Error> error { get; set; }
}
my Json result is like this
{"error":[{"id":"15006","code":"Error CODE","message":"Error Message","qty":""}]}
and I map the json string to my object like this
RootObject obj =JsonConvert.DeserializeObject<RootObject>(jsonString);
My question is the id and qty fields. The json result wraps the id and qty in quotes making it a string but I want this to be a long datatype. I need this as I'm using a library to export this data to Excel and I'm having issues as is exporting it as text instead of numeric. Also the qty is empty when there is no value instead of 0. I tried long? and int? but while this works, I prefer to default to 0 if the result is empty.
I can't change the json result. I have tried converting the string to int64 in the get{} but I'm getting errors.
public long id {
get
{
var idCode = Convert.ToInt64(this.id);
return idCode;
}
}
Any ideas how I can do this? Keep in mind that I have many other fields like this.