2017-02-22 19 views
0

我不能逗號JSON,因爲逗號刪除,例如123,99由12399.在JSON逗號反序列化數爲十進制

我也發現了類似的問題,以我的替換反序列化數爲十進制: Handling decimal values in Newtonsoft.Json 但我的是比較容易的,因爲它是一個標準數字,其中點是逗號,我不需要使用特定的文化進行解析。我怎樣才能做到這一點?

public class PriceModel 
{ 
    public decimal Price { get; set; } 
} 

string json = @"{'Price': '1234,99'}"; 
PriceModel priceModel = JsonConvert.DeserializeObject<PriceModel>(json); 

回答

3

其對當前線程文化..

的en-US分隔符爲 「」 ..

 PriceModel value = JsonConvert.DeserializeObject<PriceModel>("{'Price': '1234,99'}", new JsonSerializerSettings 
     { 
      // tr culture separator is ",".. 
      Culture = new System.Globalization.CultureInfo("tr-TR") 
     }); 

和檢查。 https://msdn.microsoft.com/tr-tr/library/3ebe5aks(v=vs.110).aspx

+0

請替換鏈接: https://msdn.microsoft.com/en-us/en-en/library/3ebe5aks(v=vs.110).aspx?f=255&MSPPError=-2147217396 –