我有一个JSON对象,其中一个元素的值是一个字符串。在这个字符串中有字符"<RPC>"
。我将整个JSON对象带到ASP.NET服务器端代码中,然后执行以下操作将名为rpc_response
的对象添加到POST响应数据中:
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Cache-Control", "private, no-cache");
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=\"files.json\"");
HttpContext.Current.Response.Write(serializer.Serialize(rpc_response));
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.StatusCode = 200;
在对象被序列化后,我在另一端(不是web浏览器)接收到它,这个特定的字符串看起来像:\u003cRPC\u003e
。
我该怎么做才能防止这些(和其他)字符没有被正确编码,同时仍然能够序列化我的JSON对象?
</script>
时会感到困惑。有什么办法可以让 Json.NET 正确转义吗? - Brobic Vripiat