日期:2014-05-17  浏览次数:21744 次

wcf rest api的返回json中总出现\这个反斜杠
比如我现在有这么一个实例,我需要提供一个获取文件相关信息以及下载地址的接口给前端调用,我这里做法是


//IFile.cs这个是接口
[OperationContract]
[WebGet(UriTemplate="GetFileUrl?currentVersion={currentVersion}",
ResponseFormat=WebMessageFormat.Json,
RequestFormat=WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.Bare
)]
Model.FileInfo GetDownFileInfo(string currentVersion);

public class FileInfo
{
    public int FileId{get;set;}
    //... ...
    public int FileDownloadUrl{get;set;}
}


最后结果返回的json字符串竟然是这样的:
{"FileInfo":{"FileId":1,......"FileDownloadUrl":"http:\/\/localhost:5040\/FileUpload\/Head\/uhd2013112691122123032.jpg"}}


谁能告诉我这是怎么一回事吗?为什么返回的地址中不是正常的那种,而是每个/前面都多了个\??
wcf rest 地址 反斜杠

------解决方案--------------------
这个是转义字符,可能是由于为了能正常显示而带出来的,可以用正则过滤掉
------解决方案--------------------
RFC4627 - The application/json Media Type for JavaScript Object Notation (JSON)。可见以下链接(字符串定义在[Page 4]):

http://www.ietf.org/rfc/rfc4627.txt