C# 由于意外字符串(WCF+;JSON),WCF响应无效

C# 由于意外字符串(WCF+;JSON),WCF响应无效,c#,.net,wcf,json,C#,.net,Wcf,Json,我已经将WCF服务配置为使用JSON。 我有一个问题,所有条目都被转义 [ { "rel":"http:\/\/localhost:3354\/customer\/1\/order", "uri":"http:\/\/localhost:3354\/customer\/1\/order\/3" }, { "rel":"http

我已经将WCF服务配置为使用JSON。 我有一个问题,所有条目都被转义

    [
   {
      "rel":"http:\/\/localhost:3354\/customer\/1\/order",
      "uri":"http:\/\/localhost:3354\/customer\/1\/order\/3"
   },
   {
      "rel":"http:\/\/localhost:3354\/customer\/1\/order",
      "uri":"http:\/\/localhost:3354\/customer\/1\/order\/5"
   },
   {
      "rel":"http:\/\/localhost:3354\/customer\/1\/order",
      "uri":"http:\/\/localhost:3354\/customer\/1\/order\/8"
   }
]
我确信消息是有效的,默认情况下无需转义,是否可以关闭某些字段的转义

http:\localhost:3354\customer\1\order

你为什么用反斜杠。常用的方法是使用前斜杠。我希望将您的URL设置为“http://localhost:3354/customer/1/order“将解决问题。

转义斜杠

char 任何Unicode字符- 除了-“-或-或- 控制字符 \" \ \/ \b \f \n \r \t \四个十六进制数字


因此,C中的“/”变成了JSON中的“\/”

“\”是JSON中的一个控制字符。要将\包含在字符串中,必须使用/字符对其进行转义。任何JSON客户机都应该能够正确解释转义字符,这样您就不需要(而不能)对WCF代码进行任何修改


此外,普拉迪普是对的。URL使用前斜杠

您是否返回:“http:\\localhost:3354\customer\1\order”或“”?抱歉,这里的描述有误。Wcf返回“localhost:3354/customer/1/order”;是的,这是问题描述中的错误。在服务器上,我有url是。没错。Iphone开发者设法解析了这个字符串。所以问题解决了。