CSharp · Console
using System;
using Newtonsoft.Json;
public class Program
{
public static 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,
Newtonsoft.Json.Formatting.Indented,
new JsonSerializerSettings {
NullValueHandling = NullValueHandling.Ignore
});
Console.WriteLine(json);
}
}
public class Product
{
public string Name
{
get;
set;
}
public DateTime Expiry
{
get;
set;
}
public string[] Sizes
{
get;
set;
}
}