I don't see anything odd about the string behavior. The JSON representation of a string is just a string.
You don't really see any JSON notation until you serialize objects with properties as opposed to simple types.
JSON is actual javascript though, so I'm not sure what sort of serialization you're looking for, exactly.
var s = new JavaScriptSerializer();
Console.WriteLine(s.Serialize(DateTime.Now));
Console.WriteLine(s.Serialize("I like things & stuff ' \" ."));
Console.WriteLine(s.Serialize(3.14));
/* Should serialize to JSON object */
Console.WriteLine(s.Serialize(new { String = "I like things & stuff ' \" .", Date = DateTime.Now, PI = 3.14 }));
/* Should serialize to array */
Console.WriteLine(s.Serialize(new object[] { "I like things & stuff ' \" .", DateTime.Now, 3.14 }));
Output:
"\/Date(1316374642273)\/"
"I like things & stuff \u0027 \" ."
3.14
{"String":"I like things & stuff \u0027 \" .","Date":"\/Date(1316374642278)\/","PI":3.14}
["I like things & stuff \u0027 \" .","\/Date(1316374642280)\/",3.14]
There is some backstory to the funny date format.
The 'Javascript' serialization format appears to be code left over from the first attempt at serializing dates into JSON. The only place that value is actually used is in SerializeDateTime
I would imagine the team just made those methods private after determining that was a bad idea per the linked article:
The first thing we tried was to inject Date constructors in the JSON string. This is a (very) bad idea for a number of reasons. First, it simply does not conform to the JSON specs. Second, any JSON parser that validates its input before parsing it will cough on such a thing. Finally, it establishes a precedent: why would it be allowed for dates and not for arbitrary types? This would just defeat the purpose of JSON.
If you really just need to serialize an individual DateTime to Javascript, there's no reason you can't steal those couple of lines of code, but if you're serializing a complex object there are valid reasons you shouldn't be doing that.
public string SerializeDateTime(DateTime datetime)
{
DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DatetimeMinTimeTicks = time.Ticks;
var sb = new StringBuilder();
sb.Append("new Date(");
sb.Append((long) ((datetime.ToUniversalTime().Ticks - DatetimeMinTimeTicks) / 0x2710L));
sb.Append(")");
return sb.ToString();
}
If what you need is to actually use a serialized date from ASP.NET on a webpage, and you aren't using ASP.NET AJAX, that is covered in this question: How do I format a Microsoft JSON date?