.NET PostSubmitter 发送反斜杠
我正在使用 C# 将 JSON 发送到 PHP 脚本,如下所示:
string json = "{";
json += "\"prop\":\"some text\"";
json += "}";
PostSubmitter post = new PostSubmitter();
post.Url = "http://localhost/synch/notein.php";
post.Type = PostSubmitter.PostTypeEnum.Post;
post.PostItems.Add("note", json);
post.Post();
当然,我必须转义内部引号,但它们会发送到脚本!更糟糕的是:有些文本已经带有引号,因此必须将其转义为有效的 JSON。在这种情况下,我希望传输反斜杠。有什么想法可以实现这个目标吗?
I'm using C# to send JSON to a PHP-Script, like this:
string json = "{";
json += "\"prop\":\"some text\"";
json += "}";
PostSubmitter post = new PostSubmitter();
post.Url = "http://localhost/synch/notein.php";
post.Type = PostSubmitter.PostTypeEnum.Post;
post.PostItems.Add("note", json);
post.Post();
Of course I'll have to escape the inner quotes, but they get sended to the script! To make things worse: There is text, which already has quotation marks, so those must be escaped to be valid JSON. In this case I want the backslashes to be transmitted. Any idea to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不将自定义对象序列化为 json 结果。这样你就不必担心转义,框架会...这是一个使用
JavaScriptSerializer
- 使用 JavaScriptSerializer 将 C# 中的对象转换为 JSONWhy not serialize the custom object to json result. That way you don't have to worry about the escaping, the framework would... Here is an example using
JavaScriptSerializer
- Convert objects to JSON in C# using JavaScriptSerializer转义反斜杠
\\
:Escape your backslashes
\\
:糟糕,我以为 PostSubmitter 来自 .NET 框架,但它是第三方的。尽管如此:事实证明这是一个 PHP 问题。如果有人有类似的问题:在 PHP 文档中查找 get_magic_quotes_gpc。
Ooops, thought PostSubmitter is from the .NET-framework, but it's third-party. Nevertheless: Turned out that this is a PHP-problem. If someone has a similar problem: Look for get_magic_quotes_gpc in PHP-docs.