Json.Net unexpected characters (“\”) when serializing my entities

前端 未结 5 1775
野性不改
野性不改 2020-12-15 17:36

I am using the excellent Json.Net library to serialize my entities generated by entity framework. I use the following code to do so :

using (MyVoucherEntitie         


        
5条回答
  •  渐次进展
    2020-12-15 18:04

    I found the reason why I had escape characters in my string ("\"). After serializing my objects, I am returning the JSON string to the client app through a WCF. Apparently, WCF is automatically adding these characters to the string before sending it to the network. It is a default behaviour and is apparently mandatory.

    As I didn't want these escape characters, the workaround is to change the return type of the service to Stream and so, returning your JSON string inside a memory stream. It works perfectly and is quite fast.

提交回复
热议问题