Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to convert json result into 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 :: logout user firebase 
Javascript :: Use History React Router v5 app 
Javascript :: javascript style multiple properties 
Javascript :: how to print in jsp 
Javascript :: Unable to resolve module react-native-permissions 
Javascript :: print placeholder value javascript 
Javascript :: convert string in ethers.js 
Javascript :: javascript class constructor 
Javascript :: credit card regex 
Javascript :: javascript select first n elements from array 
Javascript :: js string to node 
Javascript :: On click, disable button 
Javascript :: express-generator 
Javascript :: discord.js verify 
Javascript :: spread operator merge objects 
Javascript :: .sort javascript 
Javascript :: mock a function jest react 
Javascript :: js remove property from object 
Javascript :: javascript math.pow 
Javascript :: sessionstorage array 
Javascript :: how to use ctx on canvas js 
Javascript :: array.find is not a function 
Javascript :: dociql process.env.NODE_TLS_REJECT_UNAUTHORIZED=0 
Javascript :: javascript remove single class from element 
Javascript :: i18n react meta description 
Javascript :: Prevent Double Submit with JavaScript 
Javascript :: javascript set html select value 
Javascript :: replace class js 
Javascript :: jquery selector exists 
Javascript :: react use same useState for multiple inputs 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =