I have a dynamic json
string:
[{
"Id": "1",
"Description": "Scenario 1",
"fc": "-45156,60000",
"fci": "-45156,60000",
"fcii": null,
"fciii": null,
"fciv": null,
},
{
"Id": "1",
"Description": "Scenario 2",
"fc": "-45156,60000",
"fci": "-45156,60000",
},
{
"Id": "1",
"Description": "Scenario 3",
"fc": "-45156,60000",
"fci": "-45156,60000",
"fcii": null,
},
{
"Id": "1",
"Description": "Scenario 4",
"fc": "-45156,60000",
}]
is it a good idea to search in json
object for string that contains ,
an idea
public decimal ConvertToDecimal(string s)
{
if (s.Contains(','))
{
return decimal.Parse(s.Replace(',', '.'));
}
else
return SomeDecimalValue;
}
How I can parse the string to Decimal and keep the decimal separator?
2
Answers
Change the decimal separator to
,
, You can rewrite the convert method as follows:add reference to Json.NET
APPROACH 1: The Easy way
usage:
APPROACH 2: The Ideal way
Roll your own custom
JsonConverter
usage:
you can try this code
Since nobody knows what value fc is – is it one number, or two you can change ConvertToDecimal accordingly.
Or you can deserialize it using c# class