I am facing an issue by converting JSON to c# using JSON converter. where I have a field decimal value is 10000 when converting the value is 10000.0 — how to restrict that?
using System;
using Newtonsoft.Json;
public class Program
{
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public decimal? Salary { get; set; }
}
public static void Main()
{
// Serializaion
Employee empObj = new Employee();
empObj.ID = 1;
empObj.Name = "Manas";
empObj.Salary = 10000;
// Convert Employee object to JOSN string format
string jsonData = JsonConvert.SerializeObject(empObj);
Console.WriteLine(jsonData);
}
}
Actual Result:
{"ID":1,"Name":"Manas","Salary":10000.0}
Expected Result:
{"ID":1,"Name":"Manas","Salary":10000}