I am using JsonConvert.DeserializeObject
to deserialize a Json to an object. In the Json there is "PageNumber": -1
but, after deserializing I am always getting PageNumber = 0
. I noticed all negative values will be converted to zeros.
Is there any way to get negative integers after deserializing?
Json:
{
"Pages": [
{
"A": [
{
"B": [
{
"numberone": -1,
"numbertwo": -1
},
{
"numberone": -1,
"numbertwo": -1
}
]
}
]
}
]
}
After deserializing I checked the list<B>
:
numberone = 0 and numbertwo = 0
In case someone has same problem, I fixed it like this:
var handleNegativeValues = new JsonSerializerSettings
{
FloatParseHandling = FloatParseHandling.Decimal
};
//Deserialize from json to class object
MyClass myObject= JsonConvert.DeserializeObject<MyCLass>(await _mHttpResponseMessage.Content.ReadAsStringAsync(), handleNegativeValues);
This is in C# Xamarin