I am looking for this code: https://dotnetfiddle.net/80dz3V
using System; using Newtonsoft.Json;
public class Program
{
public class Product
{
public string Name {get; set;}
public DateTime Expiry {get; set;}
public string[] Sizes {get; set;}
}
public void Main()
{
Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Sizes = new string[] { "Small" };
string json = JsonConvert.SerializeObject(product);
Console.WriteLine(json);
object str = "test";
json = JsonConvert.SerializeObject(str);
Console.WriteLine(json);
}
}
To correctly handle Product
but to return just test
and not "test"
Output:
{"Name":"Apple","Expiry":"2008-12-28T00:00:00","Sizes":["Small"]}
"test"
Wanted Output
{"Name":"Apple","Expiry":"2008-12-28T00:00:00","Sizes":["Small"]}
test
I understand I could just use a wrapper and check for as
but I am curious on what if any JSON.net options are available that can accomplish this?