0

I have the following customer class in c#:

class Customer 
{
  public int CustomerID;
  public string Name;
}

I am trying to convert the class object to Json string using Newtonsoft.Json:

Customer c = new Customer();
c.CustomerID = 1;
c.Name = "Test";
string jsonString = JsonConvert.SerializeObject(obj);

It generates:

{"CustomerID": 1, "Name": "Test"}

Is it possible to wrap Customer ID to double quotes (without changing CustomerID data type from int to string)?

{"CustomerID": "1", "Name": "Test"}
gunr2171
  • 16,104
  • 25
  • 61
  • 88
developer
  • 1,401
  • 4
  • 28
  • 73

0 Answers0