Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode the single quote/apostrophe in JSON.NET

How to encode the ' to \u0027 with JSON.NET?

So that the json string would look something like this:

{"Id":8,"CompanyName":"Jane\u0027s bakery"}
like image 307
CoffeeCode Avatar asked Nov 24 '12 14:11

CoffeeCode


1 Answers

Sample Call

 Newtonsoft.Json.JsonConvert.SerializeObject(your_object,
   Newtonsoft.Json.Formatting.None, 
   new Newtonsoft.Json.JsonSerializerSettings 
   { StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml })
like image 179
Rizwan Ahmed Avatar answered Oct 13 '22 08:10

Rizwan Ahmed