I am trying to get some data from a web server. When I go via a browser I see a response like:
[ { "x": "1" ,"y" : "2" ,"z" : "3" } ]
When I send a GET request the result comes back:
[ {\n\"x\": \"1\"\n,\"y\" : \"2\"\n,\"z\" : \"3\"\n\n}\n]\n"
The code I am using is basically:
// Create a request for the URL.
WebRequest request = WebRequest.Create(fullUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
Is there an easy way to get rid of the \n and the \ before the ” , or do I have to do some regex/string manipulation on the response?
Thanks,
Will
The ‘\’ before the quotation marks is simply what you will see in the debugger and represents an escaped quotation mark – no problem as it is for display purposes only and will not be present as a character when performing string manipulations.
The ‘\n’ character is a new-line character and this is actually there. If you do not want it in the string, you can remove it with the following: