Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert json result to datatable c#

DataTable dt = (DataTable)JsonConvert.DeserializeObject(json, (typeof(DataTable)));
Comment

how to convert json result into datatable c#

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Linq;
...

public static DataTable Tabulate(string json)
{
    var jsonLinq = JObject.Parse(json);

    // Find the first array using Linq
    var srcArray = jsonLinq.Descendants().Where(d => d is JArray).First();
    var trgArray = new JArray();
    foreach (JObject row in srcArray.Children<JObject>())
    {
        var cleanRow = new JObject();
        foreach (JProperty column in row.Properties())
        {
            // Only include JValue types
            if (column.Value is JValue)
            {
                cleanRow.Add(column.Name, column.Value);
            }
        }

        trgArray.Add(cleanRow);
    }

    return JsonConvert.DeserializeObject<DataTable>(trgArray.ToString());
}
Comment

C# Convert Json File to DataTable

 public DataTable Read(string filePath)
        {
            try
            {
                //check if json structure is okay (http://jsonlint.com)
                //generate object class http://www.jsonutils.com
             
                DataTable dt = new DataTable();
                dt = JsonConvert.DeserializeObject<DataTable>(File.ReadAllText(filePath));

                return dt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Comment

PREVIOUS NEXT
Code Example
Javascript :: join in javascript 
Javascript :: mongoose updatemany example 
Javascript :: react native api call 
Javascript :: js number to str 
Javascript :: js byte size 
Javascript :: javascript base64 to png 
Javascript :: javascript update value when slider moves javascript 
Javascript :: nodejs http 
Javascript :: let and var difference 
Javascript :: Using fetch to upload files 
Javascript :: js ,flat 
Javascript :: change events 
Javascript :: date range query knex 
Javascript :: template literal syntax 
Javascript :: how to change array element to integer in js 
Javascript :: node fetch response body 
Javascript :: deno vs nodejs 
Javascript :: mongoose patch document 
Javascript :: set time out 
Javascript :: searc and replace fcc solution 
Javascript :: javascript syntax 
Javascript :: trigger lambda function on s3 upload code 
Javascript :: how to add two times in javascript 
Javascript :: nodejs express flash message 
Javascript :: jest cannot find module 
Javascript :: regex finding exact x repetitions using {x} tool 
Javascript :: js if text contains lowercase 
Javascript :: find intersection between two object arrays javascript 
Javascript :: textcontent javascript 
Javascript :: for in loop javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =