繁体   English   中英

反序列化双精度类型变量时,JsonConvert引发“无效整数”异常

[英]JsonConvert throws a 'not a valid integer' exception when deserializing double type variable

当我尝试从JSON字符串反序列化为对象时,出现异常。

Newtonsoft.Json.JsonReaderException
Input string '106.890907 is not a valid integer. Path 'data[0].loc.coordinates[0]', line 1, position 9413.

这就是我反序列化对象的方式:

var propertiesObj =
          JsonConvert.DeserializeObject<Location>(
              jsonObject);

而且,这就是我的json的样子

{
    "coordinates":
    [
        106.890907,
        -6.149393
    ],
    "type": "Point"
}

最后,这是我声明模型类的方式:

Location.cs

public class Location
{
    public List<double> coordinates { get; set; }
    public string type { get; set; }
}

我已经在StackOverFlow上提到了这个问题,但是并没有解决我的问题, link

请帮忙。 我一直无法找到任何解决方案。 谢谢。

试试这个,更新JSON:

"loc": {
"coordinates": [
  106.890907,
  -6.149393
],
"type": "Point"
}

{
"coordinates": [
  106.890907,
  -6.149393
],
"type": "Point"
}

即从Json删除“ loc”

重新安装Windows 10之后,该错误神秘地消失了。

这是本地化问题。 您可以为JsonConvert设置CultureInfo。 我认为您的系统接受逗号(,)而不是点(。)的双精度

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM