Load Json response as XML [Resolved]

Posted by Neerajsinghmail under C# on 12/3/2015 | Points: 10 | Views : 297 | Status : [Member] | Replies : 1
Hello All,

I am consuming a rest service and getting JSON response. After receiving response , I am loading it as below-

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
httpWebRequest.Method = "GET";
httpWebRequest.Headers.Add("Authorization", token);
HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();

using (StreamReader sr = new StreamReader(response.GetResponseStream()))
var jsonResponse = sr.ReadToEnd().ToString();
XmlDocument xmlDoc = new XmlDocument();


Same code was working fine since last 4 month but suddenly its stopped working after adding one new field in the JSON response and giving the below error message -

Data at the root level is invalid. Line 1, position 1.

I have checked the JSON response but could not find any unusual thing.

Sample Json response what we are getting right now-


Please help me to get the root cause why its working fine previously and now its not working.



Posted by: Sheonarayan on: 12/3/2015 [Administrator] HonoraryPlatinum | Points: 50


As per your question, just adding one field is the problem so the most probable thing is that your placement of the field is wrong so you see that you are adding that field at right place. I tried to convert your JSON response to XML from http://techfunda.com/Tools/XmlToJson and found that your XML nodes are very strange. See if you are missing its placement properly.


Sheo Narayan

Neerajsinghmail, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response