Reputation: 328
i am trying to Deserialize JSON Data below is structure of json data
[{"empcode":"e123","joining_date":"2017-10-31T00:00:00","pfno":"pf232323","Rating":"A","emp_Type":"full","Project_name":"abcd 123bcc "C""}]
Project_name consist of double quotes character inside json
i am using newtonsoft.json for Serialize and Deserialize JSON Data
when i Deserialize JSON Data to datatable it gives error after parsing a value an unexpected character was encountered: C.
public static datatable getDataFromServer(string url)
{
HttpWebRequest req = null;
HttpWebResponse res = null;
//string url = url1 + date;
//Console.WriteLine(url);
req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
req.ContentType = "application/json; charset=utf-8";
// req = AddProxy(req);
res = (HttpWebResponse)req.GetResponse();
Stream responseStream = res.GetResponseStream();
var streamReader = new StreamReader(responseStream);
string txt = streamReader.ReadToEnd();
txt = txt.Replace("\\", "").Replace("/", "");
// txt = txt.Replace("\\", "");
// txt = txt.Replace(@"\", "");
txt = txt.Remove(0, 1);
txt = txt.Remove(txt.Length - 1, 1);
DataTable ds = GetDeserializedFrmJson(txt);
streamReader.Close();
streamReader.Dispose();
responseStream.Close();
responseStream.Dispose();
return ds;
}
public static DataTable GetDeserializedFrmJson(string data)
{
DataTable dt = (DataTable)JsonConvert.DeserializeObject(data, (typeof(DataTable)));
return dt;
}
Upvotes: 0
Views: 7040
Reputation: 77364
i am trying to Deserialize JSON Data below is structure of json data
No it's not. That's no valid JSON. The error is exactly what it said it was, there are quotes that are not escaped properly, so you have a dangling "C" that is not valid JSON.
I don't know what to tell you. Your code might be fine (didn't look at it), you need to fix your data so it's valid JSON.
Upvotes: 1