Cranialsurge Cranialsurge - 1 year ago 107
JSON Question

Incorrect URL format in JSON output via WCF service

I have a WCF service contract defined as follows:

UriTemplate =
ResponseFormat = WebMessageFormat.Json)]
HubResults GetHubContent(string language, string appType);

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:- will look like this


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

Answer Source

Escaping forward slashes is perfectly valid JSON (see , the "string" construction). If you pass , for example,


to any JSON parser (e.g. the JavaScript "eval" function), the value of myUrl will be "" (it will automatically unescape the slashes).

Or did I misunderstand your question? In this case, can you post an example of JSON that you think is broken?