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?

  • 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? – James Michael Hare May 03 '12 at 22:01
  • possible duplicate of [C# StringBuilder with Quotes (forJSON)](http://stackoverflow.com/questions/4379262/c-sharp-stringbuilder-with-quotes-forjson) – Alexei Levenkov May 03 '12 at 22:08

1 Answers1

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

Community
  • 1
  • 1
Julien
  • 3,509
  • 20
  • 35