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

前端 未结 4 1543
花落未央
花落未央 2021-02-08 18:55

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

So that the json string would look something like this:

{\"Id\":8,\"CompanyName         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-08 19:34

    Sample Call

     Newtonsoft.Json.JsonConvert.SerializeObject(your_object,
       Newtonsoft.Json.Formatting.None, 
       new Newtonsoft.Json.JsonSerializerSettings 
       { StringEscapeHandling = Newtonsoft.Json.StringEscapeHandling.EscapeHtml })
    

提交回复
热议问题