I guess that you are trying to convert the objFeedBackManagmentViewModel
model into a DataTable
. Right?
So, if you follow this post as @Plutonix suggested, You'll get the answer.
In summary:
1) First, Deserialize the JSON
using some appropriate classes:
public class OKStatus{
public int HTTPStatusCode {get; set;}
public FeedBack[] objFeedBackManagmentViewModel {get; set;}
}
public class FeedBack{
public int ID {get; set;}
public string FeedBackDetail {get; set;}
public DateTime CreateDate {get; set;}
}
2) Then put the method that @Pravin Pawar gracefully provided in the post inside a static class
like this:
public static class ExtensionMethods{
public static DataTable ToDataTable<T>(this IList<T> data)
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
for(int i = 0 ; i < props.Count ; i++)
{
PropertyDescriptor prop = props[i];
table.Columns.Add(prop.Name, prop.PropertyType);
}
object[] values = new object[props.Count];
foreach (T item in data)
{
for (int i = 0; i < values.Length; i++)
{
values[i] = props[i].GetValue(item);
}
table.Rows.Add(values);
}
return table;
}
}
3) Call the method :)
var json = "{\"HTTPStatusCode\":\"200\",\"objFeedBackManagmentViewModel\":[{\"ID\":2,\"FeedBackDetail\":\"Email :trupti.undirwade@gandhibagh.com Mobile :9503628985 Category :Product Request Message :lookingFor\",\"CreateDate\":\"2015-09-04T13:42:45\"}]}";
var result = JsonConvert.DeserializeObject<OKStatus>(json);
var table = result.objFeedBackManagmentViewModel.ToDataTable();
//table contains the datatable of the feedback model