代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Newtonsoft.Json; namespace test01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); DataColumn dcName = new DataColumn("Name"); DataColumn dcAge = new DataColumn("Age"); DataColumn dcCity = new DataColumn("City"); dt.Columns.Add(dcName); dt.Columns.Add(dcAge); dt.Columns.Add(dcCity); for (int i = 0; i < 10; i++) { DataRow dr = dt.NewRow(); dr[0] = "Name" + i; dr[1] = "Age" + i; dr[2] = "City" + i; dt.Rows.Add(dr); } string json = JsonConvert.SerializeObject(dt); this.richTextBox1.Text = json; } } }