JsonConvert throws a 'not a valid integer' exception when deserializing to a double

后端 未结 1 922
情深已故
情深已故 2020-12-31 15:34

I get an exception when I try to deserialize to an object from a JSON string.

Input string \'46.605\' is not a valid integer. Path \'LatitudeCenter\'

相关标签:
1条回答
  • 2020-12-31 16:32

    It could very well be because your regional settings use something other than a 'dot' to represent what's after the integer part of a double, such as the fr-FR culture.

    A rough guess is that the JsonConvert class uses methods for parsing numbers from .NET (there's no reason why it wouldn't after all), such as Double.TryParse. And these very method do by default, take into account your current culture.

    Try setting the culture of JsonConvert to CultureInfo.InvariantCulture.

    0 讨论(0)
提交回复
热议问题