Get Header Json from DataTable - CSharp System.Runtime.Serialization.Json

CSharp examples for System.Runtime.Serialization.Json:Json

Description

Get Header Json from DataTable

Demo Code


using System.Web.Script.Serialization;
using System.Reflection.Emit;
using System.Reflection;
using System.Data;
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;/*from   w w  w.  j av a  2 s.c  o m*/

public class Main{
        public static string GetHeaderJson(DataTable dt)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            List<string[]> list = new List<string[]>();
            DataRow row = dt.Rows[0];
            string[] stringArr = new string[dt.Columns.Count];
            int i = 0; 
            foreach (DataColumn col in dt.Columns)
            {
                stringArr[i] = col.ColumnName;
                i++;
            }
            list.Add(stringArr);
            return serializer.Serialize(list);
        }
}

Related Tutorials