开发者

.NET PostSubmitter sends backslashes

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("not开发者_Go百科e", 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?


Why 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 \\:

json += "\\\"prop\":\\\"some text\\\"";


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜