Reputation: 347
I can't deserialize number with comma in json to decimal because comma is deleting, for example 123,99 is replaced by 12399.
I have found similar problem to mine: Handling decimal values in Newtonsoft.Json but mine is easier because it is a standard number where dot is comma, I don't need parse using specific culture. How can I do that?
public class PriceModel
{
public decimal Price { get; set; }
}
string json = @"{'Price': '1234,99'}";
PriceModel priceModel = JsonConvert.DeserializeObject<PriceModel>(json);
Upvotes: 8
Views: 17671
Reputation: 3644
It's about current thread culture.
en-US
separator is .
PriceModel value = JsonConvert.DeserializeObject<PriceModel>("{'Price': '1234,99'}", new JsonSerializerSettings
{
// tr culture separator is ","..
Culture = new System.Globalization.CultureInfo("tr-TR") //Replace tr-TR by your own culture
});
and check this. https://msdn.microsoft.com/en-us/en-en/library/3ebe5aks(v=vs.110).aspx?f=255&MSPPError=-2147217396
Upvotes: 19