Mukesh

Mukesh

  • NA
  • 228
  • 43.1k

How to Convert JSON to DataTable in C#

Nov 30 2018 11:00 AM
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://xml.flightview.com/fvDemoConsOOOI/fvxml.exe?a=fvxmldemoSoo1&b=thrk$xxxx&depap=xxx&depdate=xxxxxx&dephr=xxxx");
httpWebRequest.Method = WebRequestMethods.Http.Get;
httpWebRequest.Accept = "application/json; charset=utf-8";
string file;
var response = (HttpWebResponse)httpWebRequest.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
file = sr.ReadToEnd();
}
//var json = JObject.Parse(file);
var table = JsonConvert.DeserializeAnonymousType(file, new { Makes = default(DataTable) }).Makes;
if (table.Rows.Count > 0)
{
//do something
}
 
 
I am trying to do this code but i am getting exception -
 
An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll but was not handled in user code
Additional information: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
 
 
so kindely please help me urgent 
 
 

Answers (4)