none
Passing JSON result over multiple hops , JSOn string has many back slashes RRS feed

  • Question

  • Hi all,

    I have this scenario :

    1. A Rest WCF service (Main) : This is a service available to us for consumption. We do not have control over this.

    2. A Rest WCF Service (Delegate) : This is our rest service which queries the above service

    3. A MVC 3 Web API (Client) : This is a MVC control which queries the Delegate Service.

    4. A Win 8 HTML/JS app : the final app that queries Client Service

    So the data flow is :

    Main ==> Delegate ==> Client ==> App

    I use WebClient to invoke the rest endpoints and get the JSON string in the Delegate and Client services.

    WebClient client = new WebClient();
                    Stream stream = client.OpenRead(%Rest Endpoint%);
                    StreamReader reader = new StreamReader(stream);
                    String response = reader.ReadToEnd();
                   
                    client.Dispose();
    
                    return response

    The problem is that when i receive the data in the app it has many back slashes ("/") in the string and so my JSON.Parse doesnot work.

    For example if a JSOn string is in this format from Main Service :

    {"Users":[{"Name":"user999","Value":"test"},{"Name":"test2","Value":"test"}]}

    When received in app it is like this :

    {GetUserResult : {\\\"Users\\\":[{\\\"Name":\\\"user999\\\",\\\"Value\\\":"test\\\"},{\\\"Name\\\":\\\"test2\\\",\\\"Value\\\":\\\"test\\\"}]}}

    I want the JSON sting in original format and not with teh additional backlashes. I know there should be something to overcome this but I am not able to get that.

    Any suggestions would be useful.

    - Girija

    Wednesday, May 8, 2013 5:46 AM

Answers

  • Hi,

    I solved this by :

    1. When sending from WCF service send as Stream. Does not mater how many hops you have just send as stream.

    2. When sending from Cloud Services (Web API) get the stream , convert to string and send it as HttpResponseMessage.

    That works..

    - Girija

    • Marked as answer by Girija Beuria Tuesday, May 14, 2013 6:47 PM
    Tuesday, May 14, 2013 6:47 PM

All replies

  • Hi,

    I think they are escape sequences, and will not come in actual JSON data. Are you sure they are coming in actual JSON data or are you seeing them while debugging? What your JSON parser says about parsing?


    One good question is equivalent to ten best answers.

    Wednesday, May 8, 2013 6:11 AM
  • Hi,

    I solved this by :

    1. When sending from WCF service send as Stream. Does not mater how many hops you have just send as stream.

    2. When sending from Cloud Services (Web API) get the stream , convert to string and send it as HttpResponseMessage.

    That works..

    - Girija

    • Marked as answer by Girija Beuria Tuesday, May 14, 2013 6:47 PM
    Tuesday, May 14, 2013 6:47 PM
  • Hi Shyam,

    Yes they are escape characters, but the subsequent hops treat them as string literals and add further escape characters.. That is where the issue arises.

    - Girija

    Tuesday, May 14, 2013 6:48 PM