【问题标题】:some problems with converting from StringBuilder to string从 StringBuilder 转换为字符串的一些问题
【发布时间】:2012-05-04 06:04:38
【问题描述】:

我从谷歌天气中看到这样的回复

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

在调试器中字符串看起来像

<xml_api_reply version="1">

但是当我将 StringBuilder 转换为字符串时,我得到了

  <xml_api_reply version=\"1\">

它在每个" 之前添加\。有什么问题?

【问题讨论】:

标签: c#


【解决方案1】:

如果您在调试器中看到斜线,这不是问题:这是正常的。

QuickWatch/Watch 窗口将添加额外的\。如果您查看它 在 Text Visualizer 中,您不会看到它们:

快速观看:

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

Visualizer(实际输出):

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

\ 表示引号已被转义,将被 像您期望的那样包含在最终字符串中。 IE。 您的输出没有问题

来源:https://stackoverflow.com/a/4379353/1220876

【讨论】:

  • hm...所以它不会导致ArgumentException(Illegal characters in path)...奇怪。
猜你喜欢
  • 2014-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-26
  • 2013-03-07
  • 1970-01-01
  • 1970-01-01
  • 2013-02-15
相关资源
最近更新 更多