I have fallowing JArray data. I need to create a datatable dynamically based on the column names in the Jarray, after that I need to insert the data.
Can you please help me to do this operation.
<pre>
{[
{
"PID": 3,
"FirstName": "parveen",
"LastName": "a",
"Gender": "male"
},
{
"PID": 8,
"FirstName": "ramarao",
"LastName": "M",
"Gender": "male"
}
]}
</pre>
Thanks in advance
purna
Your JSON input is not valid. You should remove the first and the last brackets, since it is an array, not an object. If you know the row type you should use one of the existing JSON libraries, and deserialize the array to a strongly typed list. If you don't know the type, use the toDataTable method.
I used the following library in the example:
http://james.newtonking.com/json
This worked for me:
With a valid JArray the following code should do what you want.
DataTable MyTable = JsonConvert.DeserializeObject<DataTable>(YOURJARRAY.ToString());
You will need to name the table.