JSON (JavaScript Object Notation) adalah format pertukaran data yang ringan, mudah dibaca dan ditulis oleh manusia, serta mudah diterjemahkan dan dibuat (generate) oleh komputer.
Berikut ini saya berikan contoh sample code generate string JSON menggunakan bahasa C#
using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace VERSI02 { public class LogEntry { public string Details { get; set; } public DateTime LogDate { get; set; } } class Program { static void Main(string[] args) { LogEntry entry = new LogEntry { LogDate = new DateTime(2009, 2, 15, 0, 0, 0, DateTimeKind.Utc), Details = "Application started." }; string isoJson = JsonConvert.SerializeObject(entry); JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; string microsoftJson = JsonConvert.SerializeObject(entry, microsoftDateFormatSettings); string javascriptJson = JsonConvert.SerializeObject(entry, new JavaScriptDateTimeConverter()); Console.WriteLine(javascriptJson); Console.Read(); } } } |