0

I read response from google weather like this

using (StreamReader streamreader = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding(1251)))
        {
            sb.AppendLine(streamreader.ReadToEnd());
            sb.Remove(0, 21);

In debugger string looks like

<xml_api_reply version="1">

but when I convert StringBuilder to string I've got

  <xml_api_reply version=\"1\">

It adds \ before every ". What's the problem?

2
  • 5
    you see the "\" in the debugger when you analyze the string? Or you output the string and it has the \ in the actual output? Commented May 3, 2012 at 22:01
  • possible duplicate of C# StringBuilder with Quotes (forJSON) Commented May 3, 2012 at 22:08

1 Answer 1

2

If you see the slashes in the debugger, it's not a problem: it's normal.

The QuickWatch/Watch window will add the extra \ in. If you view it in the Text Visualizer, you will not see them:

QuickWatch:

"{  \"data\": {  \"urls\": [  {\"url\": \"domain/path1\"}  ,{\"url\": 
    \"domain/path2\"}  ]  }}"

Visualizer (the actual output):

{  "data": {  "urls": [  {"url": "domain/path1"}  ,{"url": "domain/path2"}  ]  }}

The \ indicates that the quotes have been escaped and will be included in the final string as you're expecting them to be. I.e. there's nothing wrong with your output.

source : https://stackoverflow.com/a/4379353/1220876

Sign up to request clarification or add additional context in comments.

1 Comment

hm...So it doesn't cause ArgumentException(Illegal characters in path)...Strange.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.