2017-05-02 108 views
0

當我嘗試從JSON字符串反序列化爲對象時,出現異常。JsonConvert在反序列化double類型變量時拋出'無效整數'異常

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

請幫忙。我一直無法找到任何解決方案。謝謝。

+0

是整個JSON?因爲這個JSON無效 – Usman

+0

不,它不是。由於機密信息問題,我只顯示它的一部分。現在我已將它更改爲正確的json。感謝您指出。對不起,我錯了。 –

+0

確實在下面的答案爲你工作? – Usman

回答

0

刪除 「祿」 我重新安裝了Windows後10,這個錯誤神祕地消失了。

0

試試這個,更新JSON:

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

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

即從Json的

+0

嗨,@Vivek。我展示了錯誤的json。我現在已將其更改爲正確的一個。對不起,我錯了。 –

-1

這是本地化問題。您可以將您的CultureInfo設置爲JsonConvert。 我認爲你的系統接受雙重昏迷(,)不與點(。)

相關問題