title: Serialising a string which contains backslashes with Json.Net
body: <p>I am trying to serialise an object which contains a UNC-Windows path to a shared ressource.</p>
  
  <p>My code:</p>
  
  <pre><code>     public class NetworkConnection
       {
          public String LocalName { get; private set; }
          public String RemotePath { get; private set; }
          public String ResourceType { get; private set; }
  
          private NetworkConnection()
          {
              LocalName = String.Empty;
              RemotePath = String.Empty;
              ResourceType = String.Empty;
          }
  
          public static List&lt;NetworkConnection&gt; getNetworkConnections()
          {
              try
              {
                  List&lt;NetworkConnection&gt; networkConnections = new List&lt;NetworkConnection&gt;();
                  ManagementObjectSearcher searcher =
                      new ManagementObjectSearcher("select * from Win32_NetworkConnection");
                  foreach (var item in searcher.Get())
                  {
                      NetworkConnection con = new NetworkConnection();
                      con.LocalName = (string) (item.GetPropertyValue("LocalName") ?? String.Empty);
  
                      con.RemotePath = (string)(item.GetPropertyValue("RemotePath") ?? String.Empty);
                      Uri uri = new Uri(con.RemotePath);
                      con.RemotePath = uri.AbsoluteUri.Replace("file://", @"\");
                      con.RemotePath = con.RemotePath.Replace('/', '\\');
                      con.ResourceType = (string) (item.GetPropertyValue("ResourceType") ?? String.Empty);
  
                      networkConnections.Add(con);
                  }
                  return networkConnections;
              }
              catch (Exception)
              {
                  return new List&lt;NetworkConnection&gt;();
              }
          }
      }
  
     class PC
      {
          public Software.Software Software { get; private set; }
          public Hardware.Hardware Hardware { get; private set; }
          public PC()
          {
              Software = new Software.Software();
              Hardware = new Hardware.Hardware();
          }
      }
  
      public class Hardware
          {
              public List&lt;NetworkConnection&gt; NetworkConnections { get; private set; } 
              public Hardware()
              {
                  NetworkConnections = NetworkConnection.getNetworkConnections();
              }
          }
  
  //Serialising
         PC pc = new PC();
         using (StreamWriter writer = new StreamWriter("deimama.txt"))
         {
             writer.WriteLine(JsonConvert.SerializeObject(pc, Formatting.Indented));
         }
  </code></pre>
  
  <p>Output (shortened):</p>
  
  <pre><code>\\192.168.1.1\\speech
  </code></pre>
  
  <p>Wanted Output:</p>
  
  <pre><code>\\192.168.1.1\speech
  </code></pre>
  
  <p>PS: I tried different ways with string replacing as well</p>