\ character in JSON string

Dec 14, 2011 at 5:49 PM

I have written some very simple code to createa  JSON string as follows:

StringBuilder sb = new StringBuilder();      
StringWriter sw = new StringWriter(sb);

using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
    jsonWriter.Formatting = Formatting.None;
                        
    jsonWriter.WriteStartArray();
    while (reader.Read())
    {
        jsonWriter.WriteStartObject();
        jsonWriter.WritePropertyName("temp");
        jsonWriter.WriteValue(((short)reader[3] / (double)10).ToString());
        jsonWriter.WritePropertyName("time");
        jsonWriter.WriteValue(DateTime.Parse(reader[2].ToString()).ToString("HH:mm:ss"));
        jsonWriter.WriteEndObject();
    }
    jsonWriter.WriteEnd();
}

return sb.ToString();

So, when I run this and get my string back I get the following:

[{\"temp\":\"41.3\",\"time\":\"10:54:00\"},{\"temp\":\"41.3\",\"time\":\"10:53:30\"}]

 Why are there the \ characters in there?  Is there a way to get rid of them?  The system I am sending this JSON string to doesn't like the \ characters.

I spent some time on this board and couldn't find the answer - sorry if I missed it.