Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning raw json (string) in wcf
    primarykey
    data
    text
    <p>I want to build my own JSON, and have the service return a string, here is the code </p> <pre><code>[OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] public string GetCurrentCart() { //Code ommited string jsonClient = null; var j = new { Content = response.Content, Display=response.Display, SubTotal=response.SubTotal}; var s = new JavaScriptSerializer(); jsonClient = s.Serialize(j); return jsonClient; } </code></pre> <p>The response I am getting contains the \" used to create "'s in strings in c#.</p> <p>The following is the response.</p> <pre><code>"{\"Content\":\"\\r\\n\\u003cdiv\\u003e\\r\\n\\u003cinput type=\\\"hidden\\\" name=\\\"__VIEWSTATE\\\" id=\\\"__VIEWSTATE\\\" value=\\\"\/wEPDwUBMA9kFgJmD2QWAmYPZBYGAgMPFgIeBFRleHQFKFlvdSBoYXZlIG5vIGl0ZW1zIGluIHlvdXIgc2hvcHBpbmcgY2FydC5kAgUPFgIeB1Zpc2libGVoZAIHDxQrAAIPFgIfAWhkZGQYAQUMY3RsMDEkbHZDYXJ0D2dkoWijqBUJaUxmDgFrkGdWUM0mLpgQmTOe8R8hc8bZco4=\\\" \/\\u003e\\r\\n\\u003c\/div\\u003e\\r\\n\\r\\n\\u003cdiv class=\\\"block block-shoppingcart\\\"\\u003e\\r\\n \\u003cdiv class=\\\"title\\\"\\u003e\\r\\n \\u003cspan\\u003eShopping Cart\\u003c\/span\\u003e\\r\\n \\u003c\/div\\u003e\\r\\n \\u003cdiv class=\\\"clear\\\"\\u003e\\r\\n \\u003c\/div\\u003e\\r\\n \\u003cdiv class=\\\"listbox\\\"\\u003e\\r\\n You have no items in your shopping cart.\\r\\n \\r\\n \\r\\n \\u003c\/div\\u003e\\r\\n\\u003c\/div\\u003e\\r\\n\",\"Display\":\"You have no items in your shopping cart.\",\"SubTotal\":null}" </code></pre> <p>The values are being correctly encoded, but the json itself is not properly formatted. These \'s cause it to go out of wack.</p> <p>How do I return a string without the \'s in front of the "'s?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload