title: Serializing strings containing apostrophes with JSON.Net
body: <p>I am using JSON.Net as my serializer for a large MVC 3 web application in c# and the Razor view engine. For the initial page load in one view, there is a large amount of JSON dumped inside a script tag using <code>@Html.Raw(JsonConvert.SerializeObject(myObject))</code>.</p>
  
  <p>The problem is that some values of some objects contain apostrophes (think names like O'Brien), which JSON.Net is not escaping or encoding in any way.</p>
  
  <p>It's not an option to pre-encode the values stored in the database because that vastly complicates various other processes.</p>
  
  <p>Is there a way to force JSON.Net to HTML encode the values of the objects that it serializes, the same way that the built-in JavaScriptSerializer does when you call <code>JavaScriptSerializer.Serialize(myObject)</code>?  Or, is there a way to deal with this in the view?</p>