Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:57:11+00:00 2026-05-27T05:57:11+00:00

I have a .Net WCF Rest service returning Json to be consumed by an

  • 0

I have a .Net WCF Rest service returning Json to be consumed by an Android app.

In debug, the WCF service correctly has the return value (Json) as:

{"BaseLoyaltyPoints":1480,"BonusLoyaltyPoints":0,"BrandId":1414, [etc...] }

Also in debug, when it returns to Notepad, the return value has changed to:

{\"BaseLoyaltyPoints\":1480,\"BonusLoyaltyPoints\":0,\"BrandId\":1414, [etc...] }

And when it gets to my Android app, it has become:

{\\"BaseLoyaltyPoints\\":1480,\\"BonusLoyaltyPoints\\":0,\\"BrandId\\":1414, [etc...] }

This is the boilerplate code I am using to serialize the Json:

Dim stream1 As MemoryStream = New MemoryStream
Dim ser As DataContractJsonSerializer = New DataContractJsonSerializer(GetType(FullProduct))
ser.WriteObject(stream1, Me)

Dim _json As String = Encoding.UTF8.GetString(stream1.ToArray())
stream1.Close()

The Android code to get the Json is:

HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(getString(R.string.CONST_RestService) + "/json/Product/" + productID);
ResponseHandler<String> handler = new BasicResponseHandler();       
result = httpclient.execute(request, handler);  
jObject = new JSONObject(result);

What’s going on?

Thanks

Dave

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:57:12+00:00Added an answer on May 27, 2026 at 5:57 am

    The JSON Data needs to be an evaluable JavaScript String – the ” character needs to be escaped to \” (the character ” as opposed to the String limitor “), and the \ in that expression needs to be escaped as well (because \ also is a special character). So it has been that string all along, it was just printed differently everytime.

    Take this JavaScript for an example:

    object = JSON.parse("{\"hello\":\"World\"}");
    alert(object.hello);
    

    The following is more of a guess than actual knowledge, because I do not know how exactly the classes you used behave, but I think that it’s about right.

    As you can see, the " characters need to be escaped to \", so your .NET JSON serializer does just that. Everything is fine, interpreting this as JS would work as expected.

    Now what is probably going on is that your JSONObject constructor does not expect Strings to be already properly escaped, so it does that itself. To clarify: When you say “with one escape character”, you probably mean something like this:

    String workingJSONString = "{\"Hello\":\"World\"}"
    

    right? The problem here is that Java has the same escaping rules as JavaScript – this is not what you get from your HTTPRequest, what you get is

    String youGotThis = "{\\\"Hello\\\":\\\"World\\\"}"
    

    Because there are literal backslashes in your String, and those need to be escaped as well. I am pretty certain that that is what is going on, and you’d probably either have to tell your .NET JSON serializer not to apply escape rules or find something that constructs a JSONObject from a properly escaped JSON string – or remove the unnecessary escapes yourself.

    I hope this helped – but again, I am not fully certain so you should just check out if it actually behaves as I said.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST service consumed by a .Net WCF client. When an error
I have an iPhone simulator app as client and WCF-REST, json encoded service running
Friends, I'm lost here. I have this WCF Rest service returning data in json
I have a WCF service hosted that is returning a byte[] of protobuf-net serialized
I have trying to design a REST service in .NET 3.5 with WCF REST
I have a WCF REST Service which accepts a JSON string One of the
I have deployed an asp.net site with a wcf rest service to a virtual
I have a WCF rest service using webHttpBinding that returns JSON result. The problem
I created a new wcf rest service using .net 4. I have created a
I have a .NET 4.0 WCF REST service (to generate and validate product keys)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.