通过WCF服务在JSON中输出的URL格式不正确 [英] Incorrect URL format in JSON output via WCF service

查看:87
本文介绍了通过WCF服务在JSON中输出的URL格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务合同,定义如下:

I have a WCF service contract defined as follows:

[OperationContract]
    [WebGet(
        UriTemplate =
            "HubContent/{language}?apptype={appType}"
        ,
        ResponseFormat = WebMessageFormat.Json)]
    HubResults GetHubContent(string language, string appType);




为了在服务中实现此合同,我返回了一个用JSON解析出来的对象的List.但是,只要对象的属性之一是URL或任何包含正斜杠的字符串,浏览器中服务返回的JSON都会转义正斜杠.所以这个网址:-http://www.xxx.com/test/site看起来像这样

http \/\/www.xxx.com \/test \/site.

我需要在与格式相关的合同中指定一些内容来纠正此问题吗?




In the implmentation of this contract in the service, I return a List of objects that gets parsed out in JSON. However whenever one of the properties of the objects is a URL or any string that contains forward slashes the JSON that is returned by the service in the browser escapes the forward slashes. So this url:- http://www.xxx.com/test/site will look like this

http\/\/www.xxx.com\/test\/site.

Is there something I need to specify maybe in the contract related to formatting to rectify this ?

推荐答案

我刚刚发现JSON解析器将读取上述URL就可以了.问题已解决.
I just found out that a JSON parser will read the above URL just fine. Problem solved.


这篇关于通过WCF服务在JSON中输出的URL格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆